作者:瑶2012瑶_881 | 来源:互联网 | 2023-05-18 15:51
Iwantedtohaveamacroonworkbook1thataskedtheusertoopenaworkbook(workbook2)thathason
I wanted to have a macro on workbook1 that asked the user to open a workbook (workbook2) that has only one sheet from which to copy all the data to sheet "Import" in workbook1.
我希望在workbook1上有一个宏,该宏要求用户打开一个工作簿(workbook2),该工作簿只有一个工作表,从中可以将所有数据复制到workbook1的“导入”中。
My code is as follows
我的代码如下
Sub test()
Dim NewWB As Workbook
Dim Vfile As Variant
Vfile = Application.GetOpenFilename("Excel-files,*.xls", 1, "The Import _
sheet is empty, please select ME3M data to import", , False)
If Vfile = False Then Exit Sub
Set NewWB = Workbooks.Open(Vfile)
NewWB.Sheets(1).Cells.Copy Destination:=ThisWorkbook.Sheets("Import").Range("A1")
NewWB.Close
End Sub
My problem is that the file I need to open is in xls and the one with the macro on (on which I want to copy the data) is in xlsx and I suspect this creates some problems because there are some cells that contain numbers the just change their value if opened through vba.
我的问题是,我需要打开的文件是xls和宏观的(我想复制数据)xlsx,我怀疑这造成了一些问题,因为有一些包含数字的单元格,如果打开通过vba只是改变他们的价值。
For example in one cell there is the number 1.500 (one thousand five hundred) and if I open that file the old fashion way by clicking it that's what I see; but If I get it opened by the macro by running the above code without the last two lines the number in the cell becomes 1,5 (one and a half).
例如,在一个单元格中有1。500(1500)如果我按下它来打开旧的格式,这就是我看到的;但是如果我通过运行上面的代码来打开它,而没有最后两行,那么单元格中的数字就变成了1 5(1。5)
1 个解决方案