如何从第一个工作簿复制后激活工作簿

时间:2014-07-09 11:14:26

标签: excel vba

在主工作簿中我启动一个按钮,打开第二个工作簿,然后返回第一个工作簿,复制一系列单元格,然后转到第二个工作簿(这里出错)粘贴

Sub Knop7_Klikken()
    Dim TelStaat As Workbook
    Dim Staat As Worksheet
    Dim WicamStaat As Workbook
    Dim Invoer As Worksheet
    Dim Pathname As String
    Dim Filename As String
    Dim Value1 As String

    'TelStaat = "Calculatie 2014 Nesting Wicam.xlsm"

    Set TelStaat = ThisWorkbook

    Value1 = "AN"
    Pathname = "V:\\2013 Calculatie\"
    Filename = "VPT.xlsm"

    'when I use this it wil not open second macro
    Application.EnableEvents = False

    Workbooks.Open Filename:=Pathname & Filename
    Worksheets("Invoer").Activate
    TelStaat.Activate
    Worksheets("Staat").Columns(3).Find(Value1).Select

    Range(ActiveCell, ActiveCell.End(xlDown)).Select
    Selection.Offset(0, 6).Select
    Selection.Resize(, 6).Select
    Selection.Copy

    'here it goes wrong,
    Set WicamStaat = ActiveWorkbook
    Worksheets("Invoer").Activate

    Range("A32").Select

    Selection.PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False

    Application.Calculation = True / xlAutomatic
End Sub

1 个答案:

答案 0 :(得分:1)

Windows("copyfromfile.xlsx").Activate 'Copy
Columns("A:H").Select 
Selection.Copy 

Windows("pastetofile.xlsx").Activate 'Paste 
Columns("A:A").Select 
Selection.Insert Shift:=xlToRight