how to import data using .odc file in Excel 2013 VBA -
i trying write vba import data query table using .odc file stored in sharepoint data connection library. used macro recorder record process add connection, go existing connections , import data table in current worksheet(which worked when did manually).
the recorder spit out following code (i removed command text since contains sensitive info, big string of sharepoint related stuff list , view guid):
sub recordedimportmacro() workbooks("myworkbook.xlsm").connections.addfromfile _ "http://path/to/my/odcfile/on/sharepoint.odc" activesheet.listobjects.add(sourcetype:=0, source:= _ "oledb;provider=microsoft.office.list.oledb.2.0;data source="""";applicationname=excel;version=12.0.0.0" _ , destination:=range("$a$1")).querytable .commandtype = 5 .commandtext = "some command text here" .rownumbers = false .filladjacentformulas = false .preserveformatting = true .refreshonfileopen = false .backgroundquery = false .refreshstyle = xlinsertdeletecells .savepassword = false .savedata = true .adjustcolumnwidth = true .refreshperiod = 0 .preservecolumninfo = true .sourceconnectionfile = "http://path/to/my/odcfile/on/sharepoint.odc" .listobject.displayname = "my_table" end end sub however, when run macro seemingly perform exact same task worked before following error: run time error 1004. googled , didn't find pertained use case
when debug following line highlighted: .commandtype = 5
any ideas on how working?
i able working using code found here
below code:
sub thisworks() activesheet.querytables.add(connection:= _ "finder;http://path/to/my/odcfile/on/sharepoint.odc" _ , destination:=range("$a$1")) .refreshstyle = xlinsertdeletecells .rownumbers = false .filladjacentformulas = false .refreshonfileopen = true .hasautoformat = true .backgroundquery = true .tablesonlyfromhtml = true .refresh backgroundquery:=false .savepassword = false .savedata = true end end sub
Comments
Post a Comment