View Single Post
 
Old 12-13-2018, 08:43 PM
Yong Xiang Yong Xiang is offline Windows 7 32bit Office 2016
Novice
 
Join Date: Dec 2018
Posts: 9
Yong Xiang is on a distinguished road
Default

Thanks, I'm still new to VBA didn't know that I can set a hardcoded constant like this.
I have tried your code but there is one error saying that couldn't find my file? Runtime error '5174'
at Selection.InsertFile FileName:=sPath & sFile, ConfirmConversions:=False,

code :
PHP Code:
Function InsertAFile(sFile As String)
  
Dim sPath as String
  sPath 
"C:\Users\YongX\Desktop\"
  Selection.InsertFile FileName:=sPath & sFile, ConfirmConversions:=False, 
  Link:=False, Attachment:=False
  Selection.TypeBackspace
End Function

Sub Add_HT_PD()
  InsertAFile "
HT PD.docx"
End Sub

Sub Add_HT_US()
  InsertAFile "
HT US.docx"
End Sub

Sub Add_TF_PD()
  InsertAFile "
TF PD.docx"
End Sub

Sub Add_TF_US()
  InsertAFile "
TF US.docx"
End Sub

Sub Add_HT()
  InsertAFile "
HT.docx"
End Sub

Sub Add_LT()
  InsertAFile "
LT.docx"
End Sub

Sub Update_Fields()
  Application.ScreenUpdating = False
  ActiveDocument.PrintPreview
  ActiveDocument.ClosePrintPreview
  Application.ScreenUpdating = True
End Sub 
Reply With Quote