I am creating a new Workbook using VBA from another Excel Workbook. I then want to perform a PrintPreviewof the new Workbook. However, the whole thing hangs. I believe this is because the PrintPreview is executed before Excel has completed creating the new Workbook. I have looked and looked and tried different things to get this to work. How can I do this. I have included several different things that I tried. See below.
NOTE: The code was originally written in Excel 2000 and works just fine!
I found the following code on the Internet somewhere:
Sub UTY_Manifest_Wait_For_Open()
Dim wb As Workbook
Set wb = Application.Workbooks.Open(fullname of just created file)
Do Until wb.ReadOnly = False
wb.Close
Application.Wait Now + TimeValue("00:00:01")
Set wb = Application.Workbooks.Open(fullname of just created file)
Loop
'Then the code that needs that Workbook open here!
'Or Call That other macro here!
ActiveWorkbook.PrintPreview (True)
End Sub
This did not work.
This is what I tried next ... which I do not like ... I don't like using a fixed wait time even though I might be able to tweak it to get it as short as possible.
Application.Wait (Now + TimeValue("0:00:04"))
ActiveWorkbook.PrintPreview (True)
This didn't work either.
I have tried all kinds of other things. Being able to do this PrintPreview has evaded me for over a year. The original code runs just fine in Excel 2000 (xls). However when running the XLS version in compatibility mode or running an XLSM version of the code in Excel 2016 it does NOT!
What will I do????? I appreciate any suggestions.
NOTE: The code was originally written in Excel 2000 and works just fine!
I found the following code on the Internet somewhere:
Sub UTY_Manifest_Wait_For_Open()
Dim wb As Workbook
Set wb = Application.Workbooks.Open(fullname of just created file)
Do Until wb.ReadOnly = False
wb.Close
Application.Wait Now + TimeValue("00:00:01")
Set wb = Application.Workbooks.Open(fullname of just created file)
Loop
'Then the code that needs that Workbook open here!
'Or Call That other macro here!
ActiveWorkbook.PrintPreview (True)
End Sub
This did not work.
This is what I tried next ... which I do not like ... I don't like using a fixed wait time even though I might be able to tweak it to get it as short as possible.
Application.Wait (Now + TimeValue("0:00:04"))
ActiveWorkbook.PrintPreview (True)
This didn't work either.
I have tried all kinds of other things. Being able to do this PrintPreview has evaded me for over a year. The original code runs just fine in Excel 2000 (xls). However when running the XLS version in compatibility mode or running an XLSM version of the code in Excel 2016 it does NOT!
What will I do????? I appreciate any suggestions.
Last edited: