Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I control the SAVE AS... Path when calling Excel 1

Status
Not open for further replies.

SLamb88

Programmer
Apr 4, 2002
9
US
I have a program, written in VB6 that allows the user to edit the incoming .CSV file using MS Excel. It does this by executing the following sub when a button is clicked:
(sFile is the name of the file to be edited)

Code:
Private Sub Excel_Edit(sFile As String)

Dim objExcel As Excel.Application
  
  Set objExcel = CreateObject("Excel.Application")
  
  With objExcel
   .Visible = True
   .Workbooks.Open sFile
  End With

End Sub

Everything works great until it's time to save the file. Then, when they click on save or save as, it tries to get them to save it in their "My Documents" folder. Since this file is out on the network, they have to go change the path before they can save it. Is there any way I can override this default setting in my program to point to the original file location?
Thanks,
Steve
 
Private Sub Excel_Edit(sFile As String)

Code:
Dim objExcel As Excel.Application
  Dim strDefPath As String
  Set objExcel = CreateObject("Excel.Application")
  'capture the users current default path so you
  ' can change it back at the end of your code
  strDefPath = objExcel.DefaultFilePath
  objExcel.DefaultFilePath = "E:\Excel"

  With objExcel
   .Visible = True
   .Workbooks.Open sFile
  End With
  'the statement below will return their default path
  ' to what it was in the beginning
  objExcel.DefaultFilePath = strDefPath
End Sub
this should do it

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top