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:
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.
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 & ";"
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.