VBA-content | new repository ( https
kandi X-RAY | VBA-content Summary
kandi X-RAY | VBA-content Summary
# VBA The content in the VBA repository is grouped first by product, then by topic. The README.md file at the root of each topic directory specifies the structure of the articles within the topic. For information about how to contribute to the VBA documentation, see Contributing.md.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of VBA-content
VBA-content Key Features
VBA-content Examples and Code Snippets
Community Discussions
Trending Discussions on VBA-content
QUESTION
I have a VBA macro to open three workbooks (call them "file0.xlsm", "file1.xlsm", and "file2.xlsm") for reading and editing.
The problem is with opening the first of these files. Whenever I start Excel and attempt to run the macro, VBA shows the error:
"Runtime Error 1004:
Sorry we couldn't find 'file0.xlsm'. Is it possible it was moved, renamed, or deleted?"
The file is in the directory and does have the correct name. (All three files are in the same directory as the workbook where the code lives.) Moreover: if I open the workbook "file0.xlsm", hit "Save As", save it with the same name, close it, and then run the VBA code, the error no longer appears.
The error appears regardless of (1) Whether the file is saved as .xlsx or .xlsm format, (2) Whether the file name is hard-coded or user-specified in a spreadsheet, and (3) the order in which I open the files.
I tried moving the data from file0 to a new workbook (by copying worksheets from file0 to the new book one at a time), and then referencing opening the new book instead of file0 in my code. The error persists.
I also checked for leading/trailing spaces in my file names, and followed the procedure on this page: https://github.com/OfficeDev/VBA-content/issues/637.
Code for opening the books:
...ANSWER
Answered 2019-Dec-28 at 02:17Your issue is that because you only specify the file name and not the path, you are attempting to open a file from the Current Directory, whatever that may be. If that directory contains a file with the specified name then that file opens (which may or may not be the file you want to open!). When an Open succeeds the Current Dirctory is updated to the directory just used.
So, you either need to verify/update the Current Directory (not reccomended) or fully qualify your path and file name.
On a side note, you've already written a helper function IsWorkBookOpen
. I'd extend that to also open the file if required, and check for correct formatting of the path and filename.
Something like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install VBA-content
Access - Download ACVBACon.chm
Excel - Download XLVBACon.chm
PowerPoint - Download PPVBACon.chm
Word - Download WDVBACon.chm
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page