麻辣家族討論版版's Archiver

connietien 發表於 2020-4-13 21:16

word表格資料複製巨集

我想把檔案1裡的表格資料複製到檔案2裡,
使用了word巨集錄製後,好像無法起作用,不知是不是哪裡有問題,
請各位高手可以幫我看一下嗎?

檔案一內容為:
名字:
住址:
電話:

巨集內容:

    Selection.MoveUp Unit:=wdLine, Count:=2
    Selection.MoveLeft Unit:=wdCharacter, Count:=3
    Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
    Selection.Copy
    Windows("2").Activate
    Selection.MoveUp Unit:=wdLine, Count:=4
    Windows("1").Activate
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=5
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=3
    Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
    Selection.Copy
    Windows("2").Activate
    Windows("1").Activate
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=3
    Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
    Selection.Copy
    Windows("2").Activate
    Selection.TypeParagraph
    Windows("1").Activate
    Selection.PasteAndFormat (wdPasteDefault)
End Sub

linyancheng 發表於 2020-4-14 21:06

為何要錄製巨集?

connietien 發表於 2020-4-14 23:45

因為是要複製檔案1特定內容到檔案2中,因為是固定抓取,想透過巨集減少重複工作

linyancheng 發表於 2020-4-18 11:51

錄製的代碼不能應付複雜的工作,譬如
selection可以指檔案1,也可以指檔案2,在檔案間使用會錯亂。
要修改,不要用selection,用documents(x).range(n,m)

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供