我被安排了一些任务,而且正如大家所说,我对此很陌生。我到处都在搜寻这些位,因此,如果我错过了任何事情,请原谅。我试过了。
所以任务的基础-
到目前为止,我有以下内容,但似乎有各种正在改变的问题?我会解释更多的不用担心-
代码-
Sub ButtonMacro()
'Hide alerts
application.displayalerts = False
'
' Macro8 Macro
'
'Save to users device
ChDir "U:\WINDOWS"
ActiveWorkbook.SaveAs Filename:="U:\WINDOWS\OrderForm.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
'Open new workbook
strFileName = "U:\OrderForm.CSV"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
objWorkbook.SaveAs (strFileName)
objExcel.Quit
'Create new workbook and populate
Workbooks.Add
ActiveCell.FormulaR1C1 = "MSG"
Range("B1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R[1]C"
Range("C1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R[1]C[3]"
Range("D1").Select
ActiveCell.FormulaR1C1 = "1400008000"
Range("E1").Select
ActiveCell.FormulaR1C1 = "501346009175"
Range("F1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Range("G1").Select
ActiveCell.FormulaR1C1 = "=Now()"
Selection.NumberFormat = "[$-x-systime]h:mm:ss AM/PM"
Range("I1").Select
ActiveCell.FormulaR1C1 = "HDR"
Range("J1").Select
ActiveCell.FormulaR1C1 = "C"
Range("K1").Select
ActiveCell.FormulaR1C1 = "1400011281"
Range("O1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!!R[1]C[3])"
Range("P1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!!R2C4"
Range("S1").Select
ActiveCell.FormulaR1C1 = "STD"
Range("T1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R5C2"
Range("V1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R7C2"
Range("W1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R8C2"
Range("Y1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R9C2"
Range("Z1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R12C2"
Range("AB1").Select
ActiveCell.FormulaR1C1 = "=POS"
Range("AE1").Select
ActiveCell.FormulaR1C1 = "=Row"
Range("AF1").Select
ActiveCell.FormulaR1C1 = "U:\WINDOWS\=[OrderForm.xlsx]Order!R15C3"
Range("AG1").Select
ActiveCell.FormulaR1C1 = "U:\WINDOWS\=[OrderForm.xlsx]Order!R15C1"
Range("AH2").Select
ActiveCell.FormulaR1C1 = "U:\WINDOWS\=[OrderForm.xlsx]Order!R15C2"
Range("AI1").Select
ActiveCell.FormulaR1C1 = "U:\WINDOWS\=[OrderForm.xlsx]Order!R15C5"
Range("AJ1").Select
ActiveCell.FormulaR1C1 = "U:\WINDOWS\=[OrderForm.xlsx]Order!R15C7"
Range("AK1").Select
ActiveCell.FormulaR1C1 = "GBP"
Range("AM1").Select
ActiveCell.FormulaR1C1 = "TRA"
Range("AP1").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(C[-3], ""POS"")+COUNTIF(C [-3], ""HDR"")"
'Reinstate alerts
application.displayalerts = True
End Sub
好的,所以我的想法是将副本保存到公用驱动器C \ TEMP中(由于业务限制,我不得不使用共享驱动器来测试U:)。
一旦在那儿写完,我只需打开一个文档并映射出正确的列即可。但是,这是所有错误的地方。
您会注意到我有一些完整和部分文件路径,这是因为我正在测试。如果我记录了一个保存文档的宏并使用它来获取部分文件路径,则这将打开保存的文档,并且不会继续。如果我使用完整路径,则会在左上方的框中获得第一个“ MSG”,然后它将停止。
整天我都得到了不同的结果。
可能有一种更整洁的方法,但我根本不知道。
需要考虑的几件事-
我们不知道可用的文件路径将永远是什么,因此我只是选择了(或将选择)C:\ windows \ temp。如果我们可以直接写信给他们的桌面,而又不知道那是最好的方法。
要保存的文档仅用于引用单元格以映射新表单。因此,实际上并不需要,但这是我知道如何映射单元格(静态文档位置)的唯一方法。
从“保存到用户设备到objExcel.Quit”的所有内容都是stuyff,我已经抓过行,尝试在打开的“ orderform.xlsx”上方打开新文档,以便尝试使用短文件路径相反,再次没有喜悦。
有点混乱。总结一下。
一个文档应该映射到另一个文档,但是该文档的文件路径未被接受,即使我已经尽力将它们记录下来以确保它们匹配并且匹配了。
起始客户表单为xlsx,但最终的映射版本应为CSV文档。
任何建议或指向支持文档的人员,将不胜感激。
答案 0 :(得分:0)
对代码的修改使其能够正常工作。下面是正确的版本。
Sub ButtonMacroLatest()
'Hide alerts
application.displayalerts = False
'
' Macro8 Macro
'
'Save to users device
ChDir "U:\WINDOWS"
ActiveWorkbook.SaveAs Filename:="U:\WINDOWS\OrderForm.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
'Create new workbook and populate
Workbooks.Add
ActiveCell.FormulaR1C1 = "MSG"
Range("B1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R[1]C"
Range("C1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R[1]C[3]"
Range("D1").Select
ActiveCell.FormulaR1C1 = "1400008000"
Range("E1").Select
ActiveCell.FormulaR1C1 = "501346009175"
Range("F1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Range("G1").Select
ActiveCell.FormulaR1C1 = "=Now()"
Selection.NumberFormat = "[$-x-systime]h:mm:ss AM/PM"
Range("I1").Select
ActiveCell.FormulaR1C1 = "HDR"
Range("J1").Select
ActiveCell.FormulaR1C1 = "C"
Range("K1").Select
ActiveCell.FormulaR1C1 = "1400011281"
Range("O1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R[1]C[3]"
Range("P1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R2C4"
Range("S1").Select
ActiveCell.FormulaR1C1 = "STD"
Range("T1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R5C2"
Range("V1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R7C2"
Range("W1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R8C2"
Range("Y1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R9C2"
Range("Z1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R12C2"
Range("AB1").Select
ActiveCell.FormulaR1C1 = "POS"
Range("AE1").Select
ActiveCell.FormulaR1C1 = "=Row()*10"
Range("AF1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R15C3"
Range("AG1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R15C1"
Range("AH1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R15C2"
Range("AI1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R15C5"
Range("AJ1").Select
ActiveCell.FormulaR1C1 = "=[OrderForm.xlsx]Order!R15C7"
Range("AK1").Select
ActiveCell.FormulaR1C1 = "GBP"
Range("AM1").Select
ActiveCell.FormulaR1C1 = "TRA"
Range("AP1").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(C[-3], ""POS"")+COUNTIF(C[-3], ""HDR"")"
'Reinstate alerts
application.displayalerts = True
End Sub