【发布时间】:2014-01-15 22:32:31
【问题描述】:
感谢任何帮助,如果我的术语不正确,请见谅。
这是一个从位置A打开文件并复制指定内容的基本宏, 然后将内容粘贴到运行此宏的当前工作簿、指定工作表和单元格中。
我的问题是关于“FileName.csv”。目前计划定期将其转储到位置 A "V:\Dir1\SubDir1\"。
如果我开始安排将其转储到 位置 B "http://172.1.2.3/Dir1/SubDir1/FileName.csv" 某个服务器种类?
我显然只是想编辑现有的宏以允许进行此更改。
Sub CopyCSVFile1()
'workbook to copy from
WBToCopy = "FileName.csv"
'workbook path to copy from
WBpthToCopy = "V:\Dir1\SubDir1\"
'workbook to paste to
'WBToPasteTo = "ResourcesV1.xlsm" not needed here as pasting to active workbook
'workbook sheet to paste to
WBSheetToPasteTo = "Raw1"
''workbook path to paste to
'WBPthToPasteTo = "N:\Engineering\Network Performance\Capacity\SG_GG\SGSN Resources\" ' not needed here as pasting to active workbook
'range to select to copy
RangeToSelectToCopy = "A3:B149"
'cell to paste to
CellToPasteTo = "A3" ' need to work this out before assignment
Dim Merged As Object
Dim Data As Object
Set Data = ActiveWorkbook
'debug.print "ActiveWorkbook.Path = " & ActiveWorkbook.Path
Debug.Print "ActiveWorkbook.Path = " & Data.Path
Sheets(WBSheetToPasteTo).Select ' this is the sheet where you want to paste to
Workbooks.Open Filename:=WBpthToCopy & WBToCopy, local:=True
Set Merged = ActiveWorkbook ' this assigns the current active workbook to merged whish is the one I want to copy from
Range(RangeToSelectToCopy).Select ' this value just for this example should be A4 normally
Selection.Copy
Data.Activate ' this activates the Data workbook which happens to be the workbook where this macro resides
Range(CellToPasteTo).Select ' select where I want to past my data
ActiveSheet.Paste ' paste the data
Application.DisplayAlerts = False
Merged.Close 'SaveChanges = False
Application.DisplayAlerts = True
End Sub
【问题讨论】: