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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel.SaveWorkspace not working... 1

Status
Not open for further replies.

jjoy123123

Programmer
Oct 22, 2002
20
US
I'm opening an excel spreadsheet from my VB code, and to avoid the user being prompted to save changes, I am trying to save the spreadsheet in the code. Here's what I've got (xlsGraph is defined as a new Excel.application):

xlsGraph.Workbooks.Open ("C:\Jennifer\Work\Habach\Code\graph_a1cbyVisit.xls")
xlsGraph.Worksheets(1).Range("a1") = "25"
xlsGraph.Calculate
xlsGraph.SaveWorkspace
xlsGraph.Visible = True
xlsGraph.WindowState = xlMaximized

However, I get the following message when it gets to xlsGraph.SaveWorkspace: "A file named RESUME.XLB already exists in this location, do you want to replace it?" The weird thing is that RESUME.XLB isn't even in the same location as the spreadhseet - RESUME.XLB is only found in C:\Jennifer). If I click on OK to replace, it seems to work fine, but I'm trying to remove any user prompts.

Any ideas on how to fix this? Even if I don't do it this way, if you have any suggestions for removing any prompts to the user, that will work as well. Thanks!
 

Your saving your entire workspace while opening and manipulating a workbook. Try this:

Dim xlApp As New Excel.Application
Dim xlWB As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Set xlWB = xlApp.Workbooks.Open("C:\Jennifer\Work\Habach\Code\graph_a1cbyVisit.xls")
Set xlSheet = xlWB.Worksheets(1)
xlSheet.Range("A1") = "25"
xlSheet.Calculate
xlWB.Save
xlApp.Visible = True
xlApp.WindowState = xlMaximized
Set xlSheet = Nothing
Set xlWB = Nothing
Set xlApp = Nothing


Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top