Cannot load image from the Windows Pictures folder into Excel file using vba -
i have vba macro add image excel file. main code add file this...
dim s shape set s = application.activesheet.shapes.addpicture(strfilename, msofalse, msoctrue, lngleft, lngtop, -1, -1) s .height = 60 .locked = true end
lngleft , lngtop coordinates set earlier in code. target image file selected using application.filedialog(msofiledialogfilepicker)
strfilename filled using following code...
dim fd filedialog dim objfile variant set fd = application.filedialog(msofiledialogfilepicker) fd .buttonname = "select" .allowmultiselect = false .title = "choose logo graphic ..." .filters.add "images", "*.gif; *.jpg; *.png; *.jpeg", 1 .filterindex = 2 .initialview = msofiledialogviewdetails .show each objfile in .selecteditems strfilename = dir(objfile, vbnormal) next objfile
problem: works on system , colleagues , random system. however, when our client, whom meant, uses it, cannot select image windows' pictures folder. can select other folder though. gets "run-time error '1004': specified file wasn't found."
all systems used in development, , testing windows 10 , client using windows 7. also, using office 2016 while using 2010.
can reason problem , workaround?
i found workaround seems job. problem piece of code
for each objfile in .selecteditems strfilename = dir(objfile, vbnormal) next objfile
when added messagebox, found strfilename has file name (eg: myimage.jpg) without full path. doesn't seem affect functioning in office 2016 on windows 10. reason, either windows 7 or office 2010 cannot work it. so, changed way file path+file name string generated , works fine.
strfilename = .selecteditems(1)
Comments
Post a Comment