truezhang 发表于 2024-5-6 10:41:24

VBA中打开EXCEL文件的怪现象

本帖最后由 truezhang 于 2024-5-6 14:05 编辑

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUQAAAChCAYAAAC/FMZDAAAMgUlEQVR4nO3dbXLjrBKGYevUu4DZcco7nh3o/AjMMKS7aT6EwLqvqqlkZBlhJX4CCKzj9+/f569fv17neb5qHMf7z/fn+fVjW7rdek6p/HS/dFv+eE3ZACD5X8+T8+CJ/z/Pr39C6/X6Dqy43Vt2Xkb6XKkc6TkA4NUViK/X9a0xAg7ALN2B+Hr97CqvVh4AeBwtY4hSYEndW2ucL91eKt8ai9SODQC1mgIRAD7Rf/Gb95tuKoBno4X4wY7j+PNzTb8HIBtyUaXkON7iuGPcrl1EmX1xxarLbvIAPM/zdRzHjTUC1vdfeZefvBdH0se1CzFSeSPV1LV2ik8MmDRs8uBJQ0kKJC2o0pZdzf4A2jW1EK0J2CP1Xi1OJ4NfceU5D6H4//yrtU++LQ/QuK10rJTWPaaVCNimdJlXcfd0HC3UUtZYnxaCtA6BMZq6zJE2z1CagyjtX1O29FipLE89eusZW10jQsnqHhN6wPW61zJr64t71xpbk7Y/dU201s2lqwvMsXWXuaYLfFXAxdbhqMCyusuEInCtrQOxFHArTaGpCbO4b2sAauHJXETA1r2WuTTGF/fxfH6i9pi2ltn7mYqlckr11MsvT7v5t3x5So53Oo42hcd7cYZABGysVPlgrFQB6mzdZYZNmusIQEcgAkBAIAJAQCACQEAgAkBAIAJAQCACQEAgAkBAIAJAQCACQEAgAkBAIAJAQCACQEAgAkAwNRBHfmDrcRwf9wnSK32gLfBEXTeZytXer7n9OGM+5y/en6WvLnNeM4DrDW0hlu7XPOPeyDOV7vtc2+IjTIF7PX4McWQ3lUAD9ja0y2yx7n8c+e7X/O8NmEr3HrHqI7Via+qk3dc5LUe7B7R1T2tvXeiuA2NNayFqb9a0m+27X/P552v6fbqt92KL1Q3W9tXCKS0nDT/rntZaGekx8jIIQ6Dfo7vM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AT/B2Z3FiIh6lcwAAAAAElFTkSuQmCC按站里大大的帮助,写了这么一段打开并显示EXCEL文件的语句。现在有个很奇怪的现象,A.xls这个文件是在资源管理里面把xlsx后缀强制改成xls得来的,AA.xls是在EXCEL里面通过另存为得来的。只运行打开A.xls,EXCEL窗口可以显示出来,但只运行打开AA.xls,窗口就显示不出来,这是为什么呀?
以下是代码


Public Sub XLTEST()

Dim fn As String

    'fn = "D:\A.xls"
    fn = "D:\AA.xls"
Dim wb As Workbook, xlapp As excel.Application
    Set wb = GetObject(fn)
    Set xlapp = wb.Application
wb.Windows(1).Visible = True

End Sub


moranyuyan 发表于 2024-5-6 12:36:18

没看描述的问题

truezhang 发表于 2024-5-6 14:07:51

补充了代码内容,奇怪之前的截图看不到。通过简单修改运行这段代码,A.xls可以显示,AA.xls没有显示窗口
页: [1]
查看完整版本: VBA中打开EXCEL文件的怪现象