如何从工作簿复制并将数据粘贴到单独工作簿的工作表上?

时间:2019-07-12 14:56:02

标签: excel vba

您好,我无法正确将数据粘贴到特定工作表中。

我尝试了多种方法来呼出工作表,但无济于事。

Sub Site_Level()
'
'


'Latest File Code
Application.ScreenUpdating = False
    Dim MyPath As String
    Dim MyFile As String
    Dim LatestFile As String
    Dim LatestDate As Date
    Dim LMD As Date

    MyPath = "C:\Users\TAmon1\Desktop\Cir\Site_Level_Crosstab"
    If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
    MyFile = Dir(MyPath & "*.csv", vbNormal)
    If Len(MyFile) = 0 Then
        MsgBox "No files were found...", vbExclamation
        Exit Sub
    End If
    Do While Len(MyFile) > 0
        LMD = FileDateTime(MyPath & MyFile)
        If LMD > LatestDate Then
            LatestFile = MyFile
            LatestDate = LMD
        End If
        MyFile = Dir
    Loop

Workbooks.Open MyPath & LatestFile
'Variables for Vlookup
Dim wbcsv As Workbook, wbplanning As Workbook
Set wbplanning = Workbooks("Planning_tool.xlsm")
Set wbcsv = Workbooks.Open(MyPath & LatestFile)
Dim wb As Workbook
Set wb = Workbooks.Open(MyPath & LatestFile)

'''''''''''''''this part is giving me problems
wb.Columns("A:G").Select
Windows("Planning_tool.xlsm").Activate
Range("A1").Select
Sheets("Sites").Paste
Columns("A:G").EntireColumn.AutoFit



wb.Close savechanges:=False

Call q_data

我得到一个对象未​​定义错误并且下标超出范围错误。我希望它可以粘贴。

0 个答案:

没有答案