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!

Saving in Excel (Not what you think)

Status
Not open for further replies.

Handcopy

Programmer
Oct 17, 2007
11
US
We have a macro that writes to Excel from Attachmate and then saves it. At least, that's what it's supposed to do. It only works when Excel is closed. However, we want it to save while the Excel window is open. But, it does not work, it ends up saving to the My Documents (default file location according to Excel). So, we tried changing location of the file to My Documents. As a result, it crashes saying that the file is read-only when it tries to save, so we scrapped that.

Basically, is there a way to save to an excel file while the window is opened?

P.S. We know about DisplayAlerts, ActiveWorkbook.Save (didn't help), and AppExcel.Save (Also,doesn't seem to help).

Thanks in advance.
 




Hi,

You really need to post your code.

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 
Here you go

Code:
Dim wbExcel As Object
Dim aSheet As Object
Dim queueID As String
Dim filePath as String
filePath="C:\documents and settings\assadk\desktop\Copy of tests2.xls"
Set AppExcel = CreateObject("Excel.Application")
Set wbExcel = AppExcel.WorkBooks.Open(filepath)
queueID= Sess0.Screen.GetString(17,18,9)
aSheet.Cells(1,9).value=queueID
AppExcel.DisplayAlerts = False
AppExcel.Save  
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
 



Code:
Set wbExcel = AppExcel.WorkBooks.Open(filepath)
queueID= Sess0.Screen.GetString(17,18,9)
[b]'where did you set aSheet???[/b][s]
aSheet.Cells(1,9).value=queueID[/s]
wbExcel.SOMESHEET.Cells(1,9).value=queueID
AppExcel.DisplayAlerts = False
[b]'the SAVE method has a WORKBOOK OBJECT as the reference[/b][s]
AppExcel.Save [/s] 
wbExcel.Save

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 
Sorry, I left out the line declaring aSheet. Here it is:

Code:
Set aSheet = wbExcel.Sheets(Sheet1)

But, the program did not act any different. Anything else?
 


please post your code again.

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 
Ok, the code was re-written specifically tp post here. Since the same error is still apparent, I don't think there's a difference.

Code:
Sub Main
    Dim appExcel As Object
    Dim wbExcel As Object
    Dim aSheet As Object
    filePath="C:\documents and settings\assadk\desktop\Copy of tests2.xls"
    Set AppExcel = CreateObject("Excel.Application")
    Set wbExcel = AppExcel.WorkBooks.Open(filepath)
    Set aSheet = wbExcel.Sheets("2.11.08")
    aSheet.cells(1, 1).value = "yo"
    AppExcel.DisplayAlerts = false
    wbExcel.Save
    AppExcel.Quit
End Sub
 
If the workbook is already open:
Set wbExcel = AppExcel.WorkBooks.Open(filepath)
opens a read only copy of the workbook.

This is probably the cause of your frustration. Try:
Set wbExcel = AppExcel.WorkBooks("Copy of tests2")




[small]Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black[/small]
 
I always perform the SaveAs when I want to determine the location. I turn off the alerts, but it's the best way I find to be specific in the save location.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top