Microsoft word vba macro insert a file with a link to a file -


i not programmer, welcome.

i want create simple script. when insert image want automatically add option link file.

i created script, problem need select file 2 times before word inserts (it adds 1 file). idea doing wrong?

sub insertlinktofile() ' ' insertlinktofile macro ' '     dim strpicname string     dim vshape inlineshape      application.filedialog(msofiledialogfilepicker) 'dialogs(wddialoginsertpicture)     .allowmultiselect = false     .title = "select file want insert"     .show     .filters.add "images", "*.gif; *.jpg; *.jpeg; *.png", 1     filetoinsert = .selecteditems(1)          if .show = -1             strpicname = .selecteditems(1)             activedocument                  set vshape = .inlineshapes.addpicture(filename:=strpicname, linktofile:=true, savewithdocument:=false)              end         end if     end  end sub 

the modified script:

    sub insertlinktofile()     '     ' insertlinktofile macro     '     '         dim strpicname string         dim vshape inlineshape      application.filedialog(msofiledialogfilepicker) 'dialogs(wddialoginsertpicture)         .allowmultiselect = false         .title = "select file want insert"       '  .show  ' remove line         .filters.add "images", "*.gif; *.jpg; *.jpeg; *.png", 1       if .show = true        filetoinsert = .selecteditems(1)        strpicname = .selecteditems(1)        set vshape = activedocument.inlineshapes.addpicture(strpicname, true, false)                  end if    end end sub 

Comments