我正在尝试将文件从一个excel文件复制到另一个excel文件。 我想将单元格中的值(存储为文本的数字)复制到新文件中作为数字本身。怎么做?我尝试了Range(“A1”)。NumberFormat =“0”但没有运气。请帮帮我。
Set myxl = CreateObject("Excel.Application")
myxl.Visible = True
Set objWorkbook2 = myxl.Workbooks.Open("C:\C.xlsx")
Set objWorkbook3 = myxl.Workbooks.Open("C:\PC.xlsx")
Set objWorksheet = objWorkbook3.Worksheets(1)
objWorksheet.Activate
set objworksheet3 = objworkbook2.worksheets.add
objworksheet3.name="Project_Overview"
Set objWorksheet2 = objWorkbook2.Worksheets("PC")
objWorksheet.Activate
objWorkSheet.Range("A1:A10").Copy
objWorkSheet2.Paste objWorkSheet2.Range("A1")
objWorkSheet2.Range("A1").NumberFormat = "0"
objWorkbook2.Save
objWorkbook2.Close
myxl.Quit
答案 0 :(得分:1)
传输值而不是复制和粘贴,并在传输之前设置目标格式。
with objWorkSheet.Range("A1:A10")
.copy destination:=objWorkSheet2.Range("A1")
objWorkSheet2.Range("A1").resize(.rows.vount, .columns.count).NumberFormat = "0"
objWorkSheet2.Range("A1").resize(.rows.vount, .columns.count) = .value2
end with