Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 12-13-2018, 09:20 PM
Guessed's Avatar
Guessed Guessed is offline How do I code bookmark globally for different template? Windows 10 How do I code bookmark globally for different template? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

That would imply that either the path or filename is wrong. The following code should replace the function I previously supplied. In this one, we are dynamically working out the path to the Desktop rather than hard coding it (which will allow it to work on other machines). It also returns a message if the passed in file doesn't exist at that location.
Code:
Function InsertAFile(sFile As String)
  Dim sPath As String
  sPath = Environ("USERPROFILE") & "\Desktop\"
  If FileExists(sPath & sFile) Then
    Selection.InsertFile FileName:=sPath & sFile, ConfirmConversions:=False, Link:=False, Attachment:=False
    Selection.TypeBackspace
  Else
    MsgBox "File doesn't exist: " & vbCr & sPath & sFile, vbOKOnly, "Missing file"
  End If
End Function

Function FileExists(sFilePath As String) As Boolean
  Dim FSO As Object
  Set FSO = CreateObject("Scripting.FileSystemObject")
  FileExists = FSO.FileExists(sFilePath)
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I code bookmark globally for different template? Field Code: Show a value only if bookmark is not empty Cosmo Word 7 08-24-2018 01:46 PM
How do I code bookmark globally for different template? VBA Code to Access Building Block Template in Word 2013 Startup folder rdross51 Word VBA 2 06-01-2016 07:05 PM
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM
How do I code bookmark globally for different template? VBA Code in template does not run in new document highrise955 Word VBA 4 03-06-2016 04:48 PM
How do I code bookmark globally for different template? Visual basic code for Word 2003 template KateAus Word VBA 4 09-09-2012 08:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft