Update embedded excel file programmatically

前端 未结 2 1858
猫巷女王i
猫巷女王i 2021-01-18 16:32

I\'m trying to modify an embedded excel table in a word document programmatically. To do this, I have modified the docx file and the embedded excel file.

The signific

2条回答
  •  遥遥无期
    2021-01-18 17:16

    Just to add to an old post in the event someone stumbles upon this like I did:

    The above code works great, but I modified it to use bookmarks instead of using SendKeys. The SendKeys statement really messes with the NumLock on my keyboard. Just one of the quirks of that command.

    What I did was create bookmarks in my Word Doc Template. Then in my code, I created a pointer to the bookmark:

    Dim bMark as bookmark
    Set bMark as ActiveDocument.Bookmarks("NameOfBookmark")
    

    Then in place of the SendKeys statement, I did the following:

    bMark.Range.Select
    Selection.EndKey
    

    This basically pulled the focus out of the embedded worksheet, and onto the bookmark of the page. Then the .EndKey statement simply removed the selection. You don't really even need it.

    Hope this helps!

提交回复
热议问题