AndyFreeman
IS-IT--Management
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
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