- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
bRecursive = False
sFolder = "C:\Users\ojoshi\Documents\sample"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oFolder = oFSO.GetFolder(sFolder)
ConvertFolder(oFolder)
oWord.Quit
Sub ConvertFolder(oFldr)
For Each oFile In oFldr.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "rtf" Then
Set oDoc = oWord.Documents.Open(oFile.path)
oWord.ActiveDocument.SaveAs oFile.path & ".pdf", 17
oDoc.Close
End If
Next
If bRecursive Then
For Each oSubfolder In oFldr.Subfolders
ConvertFolder oSubfolder
Next
End If
End Sub
This is the code I am using now. I still don't think the path is correct because I am getting the same error. the rtf file is called sample.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I tried with and without the \ at the end and it works either way.
I put the script in the same folder but I don't think that usually matters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It looks like that program is trying to loop over the files itself.
Can you get it to run directly on the machine where SAS is executing by just running from the command line? That is without using SAS at all.
If not then perhaps you can try just converting ONE file.
Can you follow these debugging steps.
1) Create a program to convert one file.
2) Run the program from the command line (on the machine where SAS runs).
3) Run the program from SAS using any of the many methods to call an operating system command from SAS code. (X, CALL SYSTEM, PIPE filename engine, etc.)
4) Try to generate a new version of the program from SAS code and test that it also runs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi
How do I change filename to remove .rtf from .pdf file created?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
oFile.path is the filename parameter being passed to the SaveAs function. You'd need to create a new variable without the extension and pass that to the SaveAs command.
Unfortunately don't have time to look into this, but some googling shows some code examples online.
SaveAs
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
bRecursive = False
sFolder = "C:\Users\userx\Desktop\test"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oFolder = oFSO.GetFolder(sFolder)
ConvertFolder(oFolder)
oWord.Quit
Sub ConvertFolder(oFldr)
For Each oFile In oFldr.Files
Filename= ofso.GetBaseName(oFile.name)
If LCase(oFSO.GetExtensionName(oFile.Name)) = "rtf" Then
Set oDoc = oWord.Documents.Open(oFile.path)
oWord.ActiveDocument.SaveAs "C:\Users\userx\Desktop\test\" & Filename & ".pdf", 17
oDoc.Close
End If
Next
If bRecursive Then
For Each oSubfolder In oFldr.Subfolders
ConvertFolder oSubfolder
Next
End If
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@smol wrote:
Hi
How do I change filename to remove .rtf from .pdf file created?
Thanks
You are better off starting your own thread. If you think this one is related then post the url as related.
Then provide the details of what you have attempted such as the code. With some description of your process there is no way for us to know where ".rtf" might be involved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I appreciate your help the other day but whatever you were explaining wasn't working on my end. Can you explain how to use DDE to do the same thing? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content