PivotMeThis
Active Member
- Joined
- Jun 24, 2002
- Messages
- 346
The following code was included in a file (named Master) that was supplied to me by another MrExcel user. I have used it for several years and it has always worked perfectly. We have moved to Office 2007 but the reports I have been using have continued to come to me as .xls files. Today I received an .xlsx file and it would not work. I can save the file as an .xls and it will work but I would like to know if there is something I can do so that this will work with the newer format. There are other worksheets inlcuded in the file (ThisWeeksDataFile) and (LastWeeksDataFile). When I try to run the query I get this message:
Data file: ‘C:\Work\Excel Widgets\LastWeeksDate.xls’ not found.
Would you like to connect to W:\Highway\Construction\Reports\Project Status\Rhondas1 Weekly Report\LastWeeksData.xls instead?
It doesn't matter which answer I select, it opens up the VBA editor with this: ".Refresh BackgroundQuery:=False" highlighted.
Here is the code:
Thanks for any advise you might be able to offer.
Rhonda
Data file: ‘C:\Work\Excel Widgets\LastWeeksDate.xls’ not found.
Would you like to connect to W:\Highway\Construction\Reports\Project Status\Rhondas1 Weekly Report\LastWeeksData.xls instead?
It doesn't matter which answer I select, it opens up the VBA editor with this: ".Refresh BackgroundQuery:=False" highlighted.
Here is the code:
Code:
Sub UpdateQueries()
Application.ScreenUpdating = False
Dim txtThisWeeksDataFile As String, txtLastWeeksDataFile As String
txtThisWeeksDataFile = Range("DataFilePath").Value & Range("ThisWeeksDataFile").Value
txtLastWeeksDataFile = Range("DataFilePath").Value & Range("LastWeeksDataFile").Value
Worksheets("Last Week").Select
Application.Goto Reference:="LastWeeksData"
With Selection.QueryTable
.Connection = Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & txtLastWeeksDataFile & ";Mode=Share Deny Write;Extende" _
, _
"d Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Lock" _
, _
"ing Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB" _
, _
":Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Wi" _
, "thout Replica Repair=False;Jet OLEDB:SFP=False")
.CommandType = xlCmdTable
.CommandText = Array("Sheet1$")
.Refresh BackgroundQuery:=False
End With
Range("A2").Select
Worksheets("This Week").Select
Columns("A:R").Hidden = False
Application.Goto Reference:="ThisWeeksData"
With Selection.QueryTable
.Connection = Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & txtThisWeeksDataFile & ";Mode=Share Deny Write;Extende" _
, _
"d Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Lock" _
, _
"ing Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB" _
, _
":Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Wi" _
, "thout Replica Repair=False;Jet OLEDB:SFP=False")
.CommandType = xlCmdTable
.CommandText = Array("Sheet1$")
.Refresh BackgroundQuery:=False
End With
Columns("A:R").Hidden = True
Range("S2").Select
Application.ScreenUpdating = True
End Sub
Thanks for any advise you might be able to offer.
Rhonda