PDA

View Full Version : Open work sheet



jnevada
10-16-2008, 08:53 PM
I'm working on a Access application that opens an excel template, do some calculatge then the spreadsheet opens (final report). template and final report are not same work book.

Is this possible that the template doesn't open at all?



....
'code on Access application
Set xlwb = xlApp.Workbooks.Open("D:\path1\path2\template.xlsm")
Set xlws = xlApp.Worksheets("Data")

xlws.Range("A6:J10000").ClearContents
xlApp.ScreenUpdating = False
xlws.Visible = xlSheetHidden
....

'code on excel template

Application.ScreenUpdating = False

Sheets("Data").Select 'Data is a sheep of template.xlsm 'error here,
'runtime error 1004 -- select method
'of worksheet class failed
......



This error is because the I set xlws.Visible = xlSheetHidden.

Bob Phillips
10-17-2008, 12:58 AM
Two things,

First you are not using xlws, so when you say Sheets("Data") there is no activeworkbook that this is a worksheet within.

Second, as you say, eveything is hidden so you cannot select it. But you don't need to elect it, reference everything through xlws and you will be oay.

jnevada
10-17-2008, 08:33 AM
Thank you very much for your reply.

I don't think I stated my question clearly. How it works now is: when Export button on Access application click, the template work sheet opens first with all calculation in front of the user, then the final report open.

I don't want template to open at all. So I add code xlws.Visible = xlSheetVeryHidden. I thought it could hide template and do calculation behind screen. But it doesn't work and error received.

Thank you very much for your help

georgiboy
10-17-2008, 01:15 PM
should you not hide the sheet before you cancel screen updating anyway