Hi there
I am not advanced Vba programmer and I need your help. Could please review my code and tell how to change the DOC(template) file path ? In other words, I would like to use 3 different word templates so I can't put file path in VBA code as it is. I need to put a reference to cell where there is a file path.
A1 - C:\Users\Tom\Desktop\doc1.docx
A2 - C:\Users\Tom\Desktop\doc2.docx
A3 - C:\Users\Tom\Desktop\doc1.docx
Another thing, I would also like to add a possiblity to save DOCs and PDFs in created folder by VBA.
My current VBA code:
Thank you in advance !!!
Tomasz
I am not advanced Vba programmer and I need your help. Could please review my code and tell how to change the DOC(template) file path ? In other words, I would like to use 3 different word templates so I can't put file path in VBA code as it is. I need to put a reference to cell where there is a file path.
A1 - C:\Users\Tom\Desktop\doc1.docx
A2 - C:\Users\Tom\Desktop\doc2.docx
A3 - C:\Users\Tom\Desktop\doc1.docx
Another thing, I would also like to add a possiblity to save DOCs and PDFs in created folder by VBA.
My current VBA code:
Code:
Sub CreateWordTemplate()
Dim wdApp As Word.Application
Dim SaveName As String
Dim FileExt As String
Set wdApp = CreateObject("Word.Application")
With wdApp
'.Visible = True
'.Activate
.Documents.Add "C:\Users\name\Desktop\doc1.docx"
Range("A1", Range("A1").End(xlDown).End(xlToRight)).Copy
.Selection.GoTo What:=-1, Name:="bookmark1"
.Selection.PasteSpecial
FileExt = ".pdf"
SaveName = Environ("UserProfile") & "\Desktop\doc1.docx " & _
Format(Now, "yyyy-mm-dd hh-mm-ss") & ".pdf"
.ActiveDocument.ExportAsFixedFormat OutputFileName:=SaveName, ExportFormat:=17
SaveName = Environ("UserProfile") & "\Desktop\doc1.docx " & _
Format(Now, "yyyy-mm-dd hh-mm-ss") & ".docx"
If .Version <= 12 Then
.ActiveDocument.SaveAs SaveName
Else
.ActiveDocument.SaveAs2 SaveName
End If
.ActiveDocument.Close
.Quit
End With
Set wdApp = Nothing
End Sub
Thank you in advance !!!
Tomasz
Last edited by a moderator: