Message 1 of 11

Not applicable
01-03-2018
08:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to open an excel from a Autocad 2014 VBA, this works fine, however, I do not want the file to re-open if it is already open. I did a lot of research and found the following code, which does not work. I included the excel file for reference, you will have to update the folder if you want to run it. Again, I can open the file but I want to skip re-opening it if it is already open. input please. I have already tried varients on the
Set Test_wb = objExcel.Workbooks(Name)
using File as well does not work. I also used the code from here: https://www.experts-exchange.com/questions/28950354/My-myFile-xlsm-2010-file-is-already-open-how-can.... it seems to work fine if in excel vba.
Sub Test_Open_Excel() Dim i As Integer Dim wb, Test_wb As Workbook Dim folder, File, Name As String Set objExcel = CreateObject("Excel.Application") folder = "C:\Users\T6145M1\Desktop\Files\Programing\VBA for AutoCAD\" Name = "Conceptual_Flow_Excel.xlsm" File = folder & Name On Error Resume Next Set Test_wb = objExcel.Workbooks(Name) On Error GoTo 0 'If workbook is not opened, Test_wb will be nothing and you can attempt to open it If Test_wb Is Nothing Then Set wb = objExcel.Workbooks.Open(File, , False) objExcel.Application.Visible = True Else Set wb = objExcel.Workbooks(File) End If wb.Activate End Sub
Solved! Go to Solution.