Manipulate a file in code (VB.NET) without executing the file's macros

前端 未结 2 1930
误落风尘
误落风尘 2021-01-24 06:48

I have an Excel file that has a bunch of VBA and macro code in it. When I open the file in Excel I can choose not to \'enable\' them - so the values in the fields all stay as t

相关标签:
2条回答
  • 2021-01-24 07:19

    Is ADO any use to you? I can only give a script example, i'm afraid.

    strLinkFile = "C:\Docs\LTD.xls"
    
    Set cn = CreateObject("ADODB.Connection")
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & strLinkFile & ";" & _
           "Extended Properties=""Excel 8.0;HDR=YES;"""
    
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open "Select * from [Sheet1$A1:B5]", cn, adOpenStatic 
    
    0 讨论(0)
  • 2021-01-24 07:20
    Application.AutomationSecurity = msoAutomationSecurity.msoAutomationSecurityForceDisable
    

    Try opening the workbook after this statement. I think, this will disable macros at Application Level (not at workbook level)

    Hope that helps.

    0 讨论(0)
提交回复
热议问题