Hi All:
I need help on how to code in vb to preview excel report. I tried the following line of code, but I get an error.
EXCELOBJ.ActiveWorkbook.PrintPreview
Thanks:afrog:
Printable View
Hi All:
I need help on how to code in vb to preview excel report. I tried the following line of code, but I get an error.
EXCELOBJ.ActiveWorkbook.PrintPreview
Thanks:afrog:
Your code as shown is correct. Try
EXCELOBJ.ActiveSheet.PrintPreview
If this doesn't work we will need to see more of your code.
If the sheet is blank it will not work.
Hi BrianB:
The print Preview still does not work. Please find below my codes.
Dim EXCELOBJ As Excel.Application
Dim EXCELBOOK As Excel.Workbook ' Workbook object
Dim EXCELSHEET As Excel.Worksheet 'Worksheet object
SaveFile = ""
FileExtension = "*.xls"
SourcePath = "S:\"
FileName = Dir(SourcePath & FileExtension, vbNormal)
SaveFile = App.Path & "\Rpts\" & File
'Create Excel Object
Set EXCELOBJ = CreateObject("Excel.Application")
EXCELOBJ.Visible = False
EXCELOBJ.Workbooks.Open FileName:=App.Path & "\Rpts\" &
Set EXCELBOOK = EXCELOBJ.ActiveWorkbook
Set EXCELSHEET = EXCELBOOK.ActiveSheet
Set EXCELSHEET = EXCELOBJ.ActiveWorkbook.Sheets(1)
Set EXCELSHEET = EXCELBOOK.ActiveSheet
'I have a loop that populate and create my excel file here
'Print preview
EXCELOBJ.ActiveSheet.PrintPreview (when this line is executed, I get an error. The error is "This action cannot be completed because other application is busy.")
What do I need to do?
Thanks
:eek: :eek:
This works for me. You need to set the visible property
to true before you do a printpreview.
HTHVB Code:
EXCELOBJ.Visible = True EXCELOBJ.ActiveSheet.PrintPreview
Thanks for your help!!!:thumb:
No prob.
Don't forget to edit you original post's subject with [Resolved]