0
希望這應該是直截了當的,但我不明白我錯過了什麼。在清除「原始」工作表中列A的內容後,我在「粘貼專用」行上收到運行時錯誤。有人可以幫幫我嗎?粘貼範圍類的特殊方法失敗 - 錯誤104
Sub BACSConversion2()
Dim MyNewBook As String
Dim MySaveFile As String
Dim fileToOpen As Variant
Dim fileName As String
Dim sheetName As String
'Turn off display alerts
Application.DisplayAlerts = False
'Turn off screen updates
Application.ScreenUpdating = False
'This calls the routine to get the text file data
'Call CopyTxtFile
'Opens the folder to location to select txt file
fileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.OpenText fileName:=fileToOpen, _
DataType:=xlDelimited, Tab:=True
End If
'Creates the file name based on txt file name
fileName = Mid(fileToOpen, InStrRev(fileToOpen, "\") + 1)
'Creates the sheet name based on the active txt file
sheetName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
'Save active file as...
ActiveWorkbook.SaveAs ("S:\Accounts (New)\Management Information
(Analysis)\Phil Hanmore - Analysis\Neil Test\Test Destination Folder\" &
fileName & ".CSV")
'Selects all data in column A and copies to clipboard
Range("A1", Range("A1").End(xlDown)).Select
Selection.Copy
'Closes the workbook
'ActiveWorkbook.Close
'Open the original document where the BACS file is located
Workbooks.Open "S:\Accounts (New)\Management Information (Analysis)\Phil
Hanmore - Analysis\Neil Test\copy of bacs conversation calc.xlsx"
'Selects the worksheet called "Original"
Sheets("Original").Select
Range("A:A").ClearContents
'Paste selected values from previous sheet
Selection.PasteSpecial Paste:=xlPasteValues
'Selects appropriate worksheet - Non-MyPayFINAL
Sheets("Non-MyPay FINAL").Select
'Selects all data in column A and copies to clipboard
Range("A1", Range("A1").End(xlDown)).Select
Selection.Copy
'Add a new workbook
Workbooks.Add
'Paste selected values from previous sheet
Selection.PasteSpecial Paste:=xlPasteValues
'Build SaveAs file name
MySaveFile = Format(Now(), "DDMMYYYY") & "NonMyPayFINAL" & ".CSV"
'Save template file as...
ActiveWorkbook.SaveAs ("S:\Accounts (New)\Management Information
(Analysis)\Phil Hanmore - Analysis\Neil Test\" & MySaveFile)
'Close the new saved file
ActiveWorkbook.Close
'Selects appropriate worksheet - MyPayFINAL
Sheets("MyPay FINAL").Select
'Selects all data in column A and copies to clipboard
Range("A1", Range("A1").End(xlDown)).Select
Selection.Copy
'Add a new workbook
Workbooks.Add
'Paste selected values from previous sheet
Selection.PasteSpecial Paste:=xlPasteValues
'Build SaveAs file name
MySaveFile = Format(Now(), "DDMMYYYY") & "MyPayFINAL" & ".CSV"
'Save template file as...
ActiveWorkbook.SaveAs ("S:\Accounts (New)\Management Information
(Analysis)\Phil Hanmore - Analysis\Neil Test\" & MySaveFile)
'Close the new saved file
ActiveWorkbook.Close
'Close original source workbook
Workbooks("bacs conversation calc").Close
'Turn on display alerts
Application.DisplayAlerts = True
'Turn on screen updates
Application.ScreenUpdating = True
End Sub
更改當前正在清除剪貼板的順序。清除內容然後複製並粘貼。順便說一句,你不需要選擇'Range(「A1」,Range(「A1」)。End(xlDown))。Copy'。 – SJR
@SJR感謝您的快速回復,您能否給我一個機會的例子? – Dyhouse
清除內容後,是否需要切換回CSV文件,複製,返回到「原始」工作表,然後粘貼? – Dyhouse