PDA

View Full Version : Don't know how to rename & move file.



JohnnyBravo
08-09-2009, 06:52 PM
So basically, I'm a VBA newb and I've taken the initiative to search for some answers and come up with a very crude attempt at my project.

I have a PDF converter software installed on my home PC. When I click on the Ghost PDF Printer in Word, it takes the active document converts it to PDF and kicks it out a directory "x:\Stuff"

My little project is to try to make some things automated.
1) Rename the PDF file
2) Move the PDF file from Directory A to Directory B
3) Start Adobe Acrobat and open up the PDF file.


Sub Print_PDF()

Dim fso
Dim docName As String
Dim Fn_Curr As String
Dim Fn_New As String
Dim Dir_output As String
Dim Dir_Dest As String

Set fso = CreateObject("Scripting.FileSystemObject")
Set docName = ActiveDocument.Name
Set Dir_output = "x:\Stuff\"
Set Dir_Dest = "x:\Resumes\2009"
Set Fn_Curr = "Microsoft Word - " & ActiveDocument.Name & ".pdf"

ActivePrinter = "Ghost PDF Printer"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument
ActiveDocument.Save

'Step 2:
'Change the PDF file name:

'I don't need to know the resume was finished in Word and the file
'extension *.docx can also be deleted.
'So I would love to change "Microsoft Word - Resume_John.docx.pdf" to:
"Resume_John.pdf"

'Something like this??

Left(Len(Fn_curr)-17) & Right(Len(docName)-4) & ".pdf"

'Step 3:
'Move the file
fso.MoveFile Dir_output & Fn_curr Dir_Dest & Fn_New

'Step 4:
'Finally, open up the newly named PDF file.

shell "C:\Program Files\Adobe Reader 8.1.3\Reader\AcroRd32.exe" & Fn_New

Set fso = Nothing
Set docName = Nothing
Set Fn_Curr = Nothing
Set Fn_New = Nothing
Set Dir_output = Nothing
Set Dir_Dest = Nothing

End Sub
Any help would be appreciated. Thanks guys.

joms
08-10-2009, 03:17 AM
check out this link....it might help..
http://www.vbaexpress.com/kb/getarticle.php?kb_id=827