Hi
I want to use a macro which generates a postscript file and then want to use this created file. For the example i have the folowing code, which first generates a ps file and call it (test.txt) and then wants to open it with notepad.exe.
VB Code:
Private Function doPS(nameofFile As String) As String ' ' Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _ wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _ ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _ True, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _ PrintZoomPaperHeight:=0, OutputFileName:=nameofFile, Append:=False doPS = nameofFile End Function Sub test() Dim f As String 'f = doPS("C:\test.txt") '..................(1) 'f = "C:\test.txt" '..................(2) Shell "notepad.exe " & f End Sub
When executing this macro on a .doc file (which contains some text): uncommenting (1): opens notepad with an empty file (so it does not considerate the generated file test.txt)
now comment (1 ) and uncomment (2) (C:\text.txt exists!) and notepad opens the test.txt perfectly!
I think it may be a synchronisation problem: shell() executes before doPS() finishes, I searched if there was a wait() function in VBA which waits until doPS() finishes and the Shell() begins...Is there a way to cure this problem? (of course I want to use one and only one macro to do these tasks! )
thanx for reading this thread![]()




Reply With Quote