
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a problem that is driving me insane. We have a program that was written in VBA in our office. It auotmaticallly selects an excel file and then generates drawings based on what's in the file. What we want to do is add a file explorer option so that somebody could select a file rather than having it automatically select. I have seen and tried the suggestions posted here http://forums.augi.com/showthread.php?153961-VBA-Autocad-Office-64-bit-Open-File-dialog-box-using-co..., here https://forums.autodesk.com/t5/visual-basic-customization/vba-open-file-with-dialog-box/td-p/1726554, and here http://forums.autodesk.com/t5/inventor-customization/folder-browser-needed-for-vba-7-64-bit/m-p/4365... but I am not too familier with running class modules and everytime I run those options it does nothing. It supposedly executes the code but I get no errors and no dialog box pops up. The solution I ended up finding was to use a send command and send a LISP getfiled command. This worked fine with AutoCAD 2015. It does not work with AutoCAD 2016 SP1 though. In 2016, when I run this from a drawing with a VBARUN I get "Error # -2145386296 : Invalid execution context." If I instead run this from the VBA IDE it works perfectly, no errors. Has anyone encountered a similar problem? Any other suggestions on a working file selection dialog box would also be helpful.
Here is the code I am running for my file dialog. The bold line throws the error.
'Make sure users1 variable gets reset ThisDrawing.SendCommand "(setvar " & """users1""" & """"") " 'Using the SendCommand method, send getfiled AutoLISP expressions to the AutoCAD command line. 'Set the return value to a user-defined system variable USERS1. ThisDrawing.SendCommand "(setvar " & """users1""" & "(getfiled " & """Select a DWG File""" & """""" & """xlsm""" & "8)) " 'Use the GetVariable method to retrieve this system variable to store the selected file name excelFilePath = ThisDrawing.GetVariable("users1")
Solved! Go to Solution.