2014-01-15 88 views
0

Apreciate任何幫助,如果我的術語不正確,請原諒我。VBA - 更改從目錄複製到從服務器複製

這是從loacation一個和複製指定的內容, 然後粘貼內容到當前工作簿,指定工作表和單元格,已運行此宏打開一個文件一個基本的宏。

我的問題是圍繞「FileName.csv」。目前預定定期在位置A「V:\ Dir1 \ SubDir1 \」中傾倒。

我怎麼會去檢索這個文件,「FileName.csv」,如果我開始安排它在loacation乙"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 

回答

0

這爲我工作:

Sub CopyCSVFile1() 

    Dim wb As WorkBook, WBToCopy As String, WBpthToCopy As String 

    'workbook to copy from 
    WBToCopy = "test.csv" 

    'workbook path to copy from 
    WBpthToCopy = "http://127.0.0.1/testpages/" 

    'open the source workbook 
    Set wb = Workbooks.Open(WBpthToCopy & WBToCopy) 

    '... 
    'do something with wb... 
    '... 

    wb.Close False 

End Sub 
+0

TKS添我會給一個去。 – HattrickNZ

相關問題