因為更新程式碼,用新文章比較好處理,如果傷眼,請見諒。 根據N大與S大的指導,我將程式碼更新如下。但是Excel還是不吃。 應該是有完成複製,但是沒有完成貼上。 Private Sub CommandButton2_Click() '=======================找尋絕對路徑與讀檔=========== Dim dpath As String Dim Fname As String Dim index_row As Integer Dim index_column As Integer Dim x As Integer Dim fileA As Workbook dpath = ThisWorkbook.Path MsgBox ThisWorkbook.Path Fname = Range("B1").Value Workbooks.Open Filename:=dpath & "\" & Fname & ".xlsx" Set fileA = Workbooks(Fname & ".xlsx") Application.Goto reference:=ActiveSheet.Range("A1") '儲存格起始座標指定 ActiveSheet.Range("A1").End(xlDown).Select '最後一筆資料定位 index_row = Selection.Row '最後一筆資料位置 index_column = Selection.Column '最後一筆資料位置 ThisWorkbook.Activate '回到A檔案 Range("B2").Copy With fileA '進到B檔案 Cells(index_row + 1, index_column).PasteSpecial End With '=================================================== End Sub ※ 引述《yimean (溫柔殺手)》之銘言: : 軟體:Excel : 版本:2013 : 小弟目前遇到兩個問題。 : 1.我要在A檔案執行VBA把A檔案的某特定儲存格寫入B檔案特定儲存格中。 : 2.我要在A檔案執行VBA把B檔案的某特定儲存格讀入A檔案特定儲存格中。 : 舉例: : A檔案worksheet1 : A B C : 1 我 是 誰 : 2 王 大 頭 : 3 知 道 嗎 : B檔案 : A B C D E F G H I : 1 我 是 誰 王 大 頭 知 道 嗎 : 取得檔案路徑我已經會了,可是我不知道應該如何寫入檔案。 : 我的核心問題是,我分不清楚此時我在A檔案還是在B檔案。 : 要如何在兩個檔案間切換。 : 下方是我的片段程式碼,煩請些助指導。 : Dim dpath As String : Dim Fname As String : Dim index_row As Integer : Dim index_column As Integer : Dim x As Integer : dpath = ThisWorkbook.Path : MsgBox ThisWorkbook.Path : Fname = Range("B1").Value : Workbooks.Open Filename:=dpath & "\" & Fname & ".xlsx" : Application.Goto reference:=ActiveSheet.Range("A1") : ActiveSheet.Range("A1").End(xlDown).Select '當我做這個動作時我應該是在B檔案了 : '那我如何切回A檔案把A檔案的資料複製起來貼到B檔案。 : 以上煩請協助,感謝。