基本上我想要实现的是将其他工作簿中的单元格值分配到我的代码中。
ShipToSiteID = Application.WorksheetFunction.Trim(Range("Q" & counter)) AltShipTo1 = Application.WorksheetFunction.Trim(Range("G" & counter)) AltShipTo2 = Application.WorksheetFunction.Trim(Range("H" & counter)) AltShipToCity = Application.WorksheetFunction.Trim(Range("I" & counter)) 'AltShipToState = Application.WorksheetFunction.Trim(Range("I" & counter)) AltShipToZip = Application.WorksheetFunction.Trim(Range("J" & counter)) AltShipToCountry = "UNITED KINGDOM" RefNumber = counter - 1 UserId = LCase(Environ("username")) ShipToSiteID = Replace(ShipToSiteID + AltShipToZip, " ", "") Sheets(2).Select Range("A" & counter - 1) = LineType & comma & RefNumber & comma & QName & comma & BlanketID _ & comma & BillToSiteID & comma & ShipToSiteID & comma & ContractID _ & comma & PONumber & comma & CaseID & comma & ShipVia & comma & RequiredDate _ & comma & Comments & comma & Priority & comma & TerminalID & comma _ & AltContactFirst & comma & AltContactLast & comma & AltPhone & comma _ & AltShipTo1 & comma & AltShipTo2 & comma & AltShipToCity & comma _ & AltShipToState & comma & AltShipToZip & comma & AltShipToCountry _ & comma & UserId & comma
答案 0 :(得分:1)
一些建议......
要在workbook1上引用workbook2中的值,最简单的方法是将工作表从workbook2复制到workbook1。然后,您可以通过在单元格中键入“=”并单击要引用的单元格来引用该值。
在VBA代码中引用可以提供更多灵活性。我建议您查看this good SO question和this one以获取更多信息。这可能更符合您的要求。
不幸的是,如果您在workbook1上引用workbook2中的值,则没有简单的方法可以从workbook1更改workbook2的值。