excel - 1004 Read-Only Error when Opening Closed Workbooks in VBA -


to give context problem i'm facing - keep in mind i'm relative novice - attempting write code open , close series of workbooks contained within folder, in order update number of vlookups on master data sheet (since update them, believe dependents need open).

right now, i'm attempting 1 of files can go through , rest of folder. when attempt open file though, "run-time error 1004" message "excel cannot access 'foldername'. document may read-only or encrypted"

the code i'm using is:

sub openevery_v2() ' openevery_v2 macro ' keyboard shortcut: ctrl+shift+o  ' dim diafolder filedialog <-- ideally user use dialog box select folder ' dim fname string ' dim originalwb workbook ' set originalwb = thisworkbook ' originalwb.save ' set diafolder = application.filedialog(msofiledialogfolderpicker) ' diafolder.allowmultiselect = false ' diafolder.show ' fname = diafolder.selecteditems(1)  fname = "c:\folderpath" openr = dir(fname + "filename.xlsm") workbooks.open (fname)  end sub 

i've tried change settings of folder non-read only, don't think issue @ hand.

has run through similar issue or can think of solution particular issue? alternatively, if there better way think through challenge, appreciated.

your code trying open file named c:\folderpathfilename.xlsm. unless file exists in root of c: drive, you'll errors.

this may more of you're after:

fname = "c:\folderpath\" openr = dir(fname & "filename.xlsm") workbooks.open (fname) 

notice:

  1. the \ added end of fname.
  2. the + replaced &. vba uses & concatenation.

of course, code sample seem cut-down version of you're executing, may not problem in real code.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -