Mass update Excel file connection string

北慕城南 提交于 2019-12-05 05:06:50

Yes you can... you make a program in c# or vb.net that loops throu all of your 600 documents and opens the documents and by using

    oModule = oBook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule)
    oModule.CodeModule.AddFromString(sCode)

and depending on your setup in the sCode variable you have a macro that loops through Excel.Connections or

    For Each wks In ActiveWorkbook.Worksheets
      For Each qt In wks.QueryTables
        With qt
          .Connection ="myconnstring" 
        End With
      Next qt
    Next wks

I wanted to do the exact same thing and came accross this tool called XLODCTool from here.

File link here.

Allos you to bulk change values inside of a connection string e.g.

DSN From SERVERA to SERVERB

Based on Archlight solution, the macro is the following :

Sub UpdateConnectionsString_Click()
   For Each wks In ActiveWorkbook.Worksheets
      For Each qt In wks.QueryTables
          With qt
           'Debug.Print .Connection
           .Connection = Replace(.Connection, "bla.com", "localhost")
          End With
      Next qt
    Next wks
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!