My company recently upgraded Office 2010 to 2016 which broke some of the automation made by a previous employee. We are running some old software that uses Access 97 and do daily exports of certain tables.
I've figured out how to open the database in Excel 2016, but when I update the macro to match the settings the scripts hangs because the Data Link Properties opens up to choose the settings instead of using the settings set in the script. Here's the script, any help is greatly appreciated.
Sub WebAdsExcelMacro()
' Don't show confirmation window
Application.DisplayAlerts = False
'
' WebAdsExcelMacro Macro
'
' Keyboard Shortcut: Ctrl+q
'
Workbooks.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.Jet.Oledb.4.0;Data Source=X:\Database\Path\DB.mdb;Password=;User ID=Admin;Mode=Sh" _
, _
"are Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet" _
, _
" OLEDB:Engine Type=4;Jet OLEDB:Database Locking 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 Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;" _
, "Jet OLEDB:Bypass UserInfo Validation=False"), Destination:=Range("$A$1")). _
QueryTable
.CommandType = xlCmdTable
.CommandText = Array("Categories")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "X:\Database\Path\DB.mdb"
.ListObject.DisplayName = "Table_Web"
.Refresh BackgroundQuery:=False
End With
Range("E1").Select
ActiveCell.FormulaR1C1 = "Title"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Desc"
Columns("C:C").Select
Selection.Replace What:=". ", Replacement:=", ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("E2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-2],FIND("", "",RC[-2])-1)"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-3],LEN(RC[-3])-FIND("", "",RC[-3]))"
Range("A3").Select
Dim WebFolder As String
WebFolder = Environ$("USERPROFILE") & "\Save\Path\"
LatestWebFolder = Environ$("USERPROFILE") & "\Save\Path\Latest\"
If Len(Dir(WebFolder, vbDirectory)) = 0 Then MkDir WebFolder
If Len(Dir(LatestWebFolder, vbDirectory)) = 0 Then MkDir LatestWebFolder
ChDir LatestWebFolder
ActiveWorkbook.SaveAs Filename:= _
LatestWebAdsFolder & "Web.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ThisWorkbook.Saved = True
For Each w In Application.Workbooks
w.Save
Next w
Application.Quit
End Sub