Sub 開啟並編輯檔案()
With Workbooks.Open(GetFileFullName).Sheets(1)
.Activate
.Cells(1, 1) = "abc"
'.Parent.Close True '關閉檔案+存檔
End With
End Sub
Function GetFileFullName() As String
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Clear '先清除可選檔案清單
.Filters.Add "Excel檔案", "*.xls*" '限定選取檔案的清單
.InitialFileName = "D:\" '選取視窗最初的資料夾位置
.AllowMultiSelect = False '單選
If .Show = 0 Then Exit Function '沒選擇就離開
GetFileFullName = .SelectedItems(1) '回傳選擇的第一個檔案的 '完整路徑'
End With
End Function作者: n7822123 時間: 2020-7-29 02:06
Sub 開啟並編輯檔案()
Dim MyFile As String
MyFile = Application.GetOpenFilename("Excel檔案,*.xls*", MultiSelect:=False)
If MyFile = "False" Then Exit Sub
With Workbooks.Open(MyFile).Sheets(1)
.Activate
.Cells(1, 1) = "abc"
'.Parent.Close True '關閉檔案+存檔
End With
End Sub作者: ssooi 時間: 2020-7-29 13:15