excel - How to open a file in a Sharepoint site using VBA -
i trying open file file name changes every week. means date part on file name varying. also, file file inside folder. file name changing. using code below throwing error, 'run time 52: bad file name & number'. need help.
dim thepath string dim thefile string thepath = "https://ts.company.com/sites/folder1/folder2/folder3/folder4/" thefile = dir(thepath & "manila_shiftrecord_*" & ".xlsx") workbooks.open (thepath & thefile)
thanks!
if it's 1 file can use approach:
dim sharepointfolder string dim coldisks variant dim objwmiservice object dim objdisk variant dim driveletter string 'create fso , network object set objnet = createobject("wscript.network") set fs = createobject("scripting.filesystemobject") 'get used drive-letters set objwmiservice = getobject("winmgmts:\\" & "." & "\root\cimv2") set coldisks = objwmiservice.execquery("select * win32_logicaldisk") 'loop through used drive-letters each objdisk in coldisks = 65 90 'if letter in use exit loop , remember letter. if = asc(objdisk.deviceid) j = exit 'letters not checked yet possible elseif > j driveletter = chr(i) & ":" exit end if next 'if drive-letter found exit loop if driveletter <> "" exit end if next 'define path sharepoint sharepointfolder = "https://spfolder/sector reports/" 'map sharepoint folder free drive-letter objnet.mapnetworkdrive driveletter, sharepointfolder 'set folder mapped sharepoint-path set folder = fs.getfolder(driveletter)
afterwards can handle folder filesystemobject functions.
Comments
Post a Comment