【发布时间】:2017-05-07 06:57:28
【问题描述】:
我将这些 Excel 单元格格式化为逗号(例如 9,000,000),我将其复制到 Word 中的固定表格中。我使用 VB 脚本来做到这一点(见下文)。但是当值进入 Word 时,逗号会消失。从 9,000,000 到 9000000。我如何才能保留该数字的原始格式?谢谢你。
Sub test()
Dim wdDoc As Word.Document
Dim wdApp As Word.Application
Dim tbl As Word.Table
Dim FileName As String
Dim iRow As Integer
Dim iCol As Integer
Path = ActiveWorkbook.Path
ChDir Path
Workbooks.Open FileName:=Path & "\Excel2.xlsx"
Set TARGET_FILE = Workbooks("Excel2.xlsx")
TARGET_FILE.Activate
Sheets("Sheet1").Select
SRC_A2 = Range("A2").Value
SRC_B2 = Range("B2").Value
FileName = "C:\Users\Desktop\Practice\Word.docx"
Set wdApp = New Word.Application
wdApp.Visible = True 'add this to see the Word instance and document
Set wdDoc = wdApp.Documents.Open(FileName)
Set tbl = wdDoc.Tables(1)
tbl.Rows(2).Cells(1).Range.Text = SRC_A2
tbl.Rows(2).Cells(2).Range.Text = SRC_B2
End Sub
【问题讨论】:
-
这似乎不是 VB 脚本(如问题中所述)或 VB.Net(如标记)。
标签: vb.net excel format copy vba