0

*sigh*

I can't get this to work. My program fills all the values into an Excel spreadsheet- no problems there. What I'd like to do is a print preview/print function. I can't seem to get my code right, all I get are blank pages in the print preview box.

Dim oExcel As Object = CreateObject("Excel.Application")
    oExcel.Workbooks.Open("C:\DailyLogs\DailyLog.xlsx")
    PrintPreviewDialog1.Document = PrintDocument1
    PrintPreviewDialog1.ShowDialog()
    oExcel.Sheet1.PrintPreview()

So as I see it, this should open excel, then navigate to the actual excel file. The print preview dialog should come up, which it does, and the excel sheet1 should be previewing, but it's not? I don't have any errors, just a blank print preview. At least thats how I see it, but obviously I'm wrong because it won't work.

Does anyone have any ideas? I've been up and down the internet with no luck.

Thanks

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by kb.net
0

Actually you just need to use:

Dim oExcel As Object = CreateObject("Excel.Application")
oExcel.Workbooks.Open("C:\DailyLogs\DailyLog.xlsx"
oExcel.Sheet1.PrintPreview()

Why are you opening the PrintPreviewDialog1??

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.