Link to home
Start Free TrialLog in
Avatar of printmedia
printmedia

asked on

Could not use "; file already in use EXCEL 2016 VBA

Hi all.

I'm getting the "Could not use "; file already in use" error when my Excel file opens, it highlights the code following the "Open connection to the workbook" comment:
Private Sub Workbook_Open()

Dim Myconnection As Connection
Dim Myrecordset As Recordset
Dim Myworkbook As String
Dim strSQL As String
Dim i As Integer
 
Set Myconnection = New Connection
Set Myrecordset = New Recordset
 
'Identify the workbook you are referencing
   Myworkbook = Application.ThisWorkbook.FullName
 
'Open connection to the workbook
   
   Myconnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Myworkbook & ";"

Open in new window


I'm using the data in first worksheet and going to do something with it in the second worksheet of the same workbook.

Any help would be appreciated.

Thank you in advance.
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

In line 13 you've set Myworkbook to be the one that you are currently using and then you try to open it again in line 17.
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of printmedia
printmedia

ASKER

I needed the double quotes in the Extended Properties section. Thanks!

I need the Myconnection.Open because later in the code I build a SQL statement with the data in sheet 1 that pivots the data.