Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving to PDF 2

Status
Not open for further replies.

AndyFreeman

IS-IT--Management
Mar 22, 2004
70
GB
I have a Macro that opens a file in a folder, then should save that file to a different folder. It also has a loop in to move onto the next file in the folder and so on.


Set objPDF = objRep.PDFFile (strfile, true)


This is the the line that is not working. It is not recognising the file name i wish to same the PDF under.

Any ideas guys.

Thanks

Below is full Macro


Sub Main()
Dim objApp As Object
Dim objRep As Object
Dim objPDF As Object

'Define variables
Dim directory, count

' for file location and counter
Dim x

' array variable
Dim strfilelocation as string ' location of account reports
Dim strfiledest as string ' location of files created
Dim strfilename(200) as string
Dim strfile as string

' filenames for reports and xl extracts
strfilelocation = "C:\Stock Sales Analysis Reports\test\"

'path to PP reports
strfiledest = "C:\Stock Sales Analysis Reports\pdf\"


'path for ppr reports
directory=Dir (strfilelocation & "*.ppr")

'way to get file names of just PP reports

Do While directory<>""
count=count+1
Strfilename(count)=directory
Strfilename(count)=Left(strfilename(count),Len(strfilename(count))-4)
'remove .ppr from the end of the path
directory=Dir
Loop
Close #1 'close file

'PART II Open Reports & save an xl version
' of the same name to the specified location
'Loop for no. of reports
For x = 1 to count
Set objApp = CreateObject ("CognosPowerPlay.Application")
Set objRep = CreateObject("CognosPowerPlay.Report")
strfile = strfilelocation+strfilename(x) & ".ppr"
objRep.Open strfile
objRep.visible( TRUE )
Set objPDF = objRep.PDFFile (strfile, true)
With objPDF
.SaveEntireReport = False
End With
objPDF.Save
objApp.Quit
Set objApp = Nothing
Set objRep = Nothing
Next x


End Sub
 
Your variable
strfile = strfilelocation+strfilename(x) & ".ppr"
I think you should change it so that it will be your PDF location with a PDF filename having a PDF extension.
 
Thanks for your quick reply

This
strfile = strfilelocation+strfilename(x) & ".ppr"
would become,

pdffile = strfilelocation+strfilename(x) & ".pdf"


how would it put the variable in the line
Set objPDF = objRep.PDFFile (strfile, true)

As it seems to ignore the variable strfile i have in there currently

Thanks
 
tiz ok i now have it saving the PDF to the correct location.

This is going to seem like a really dumb question but on

objApp.Quit

It is asking me if i want to save, where do i put the false?
 
Andy,
If you take out all the objApp references, it should work OK and not prompt to save, as you'll be opening an existing report only.

soi la, soi carré
 
have you tried with :
pdffile = strfilelocation+strfilename(x) ( without the .pdf extension )
Set objPDF = objRep.PDFFile (pdffile , True)

 
yes, all is working now.
Also used objApp.Close to fix my other bug

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top