私はこれを迅速に保ちます。ほとんどの部分の添付コードは、他のプロジェクトでわずかなバリエーションを使用して動作します。コメントアウトされた range3.copy は、私の最後のプロジェクトからのものです。
現在、選択した範囲を正しいワークブックにコピーするために selection.copy を取得する際に問題が発生しています。スクリプトに記載されている多くのことを試しました。しかし、selection.copyを機能させることができません.range.copyが機能し、クリップボードに入力されます。しかし、.copy を使用して特別に貼り付ける方法がわかりません。
変数に出力しようとしました..思ったように機能しませんでした。ワークブックの選択/アクティベーションで何かが欠けているように感じますが、何がわかりません。アドバイスや支援をよろしくお願いします..プラグインを続けて、それを理解できるかどうかを確認します。
これが問題のある最初のセグメントです。SRCrange1.select then selection.copy は、指定された選択範囲を実際にはコピーしません。完全なコードは次のとおりです。
Dim MyColumn As String
Dim Here As String
Dim AC As Variant
'SRCrange1.copy ': This will copy to clipboard
'objworkbook.Worksheets("plan").Range("b6:h7").Select no change from SRCrange1.select
'SRCrange1.Select 'the range does select
'Selection.copy ' this will cause a activecell in DSTwb _
to be copied neither direct reference to SRCrange1.select or .avtivate will change that.
DSTwb.Select
DSTwb.Range("b2").Select
Here = ActiveCell.Address
MyColumn = Mid(Here, InStr(Here, "$") + 1, InStr(2, Here, "$") - 2)
Set lastrow = ActiveWorkbook.ActiveSheet.Range(MyColumn & "65536").End(xlUp).Offset(1, 0)
lastrow.Select
Selection.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipblanks:=False, Transpose:=True
完全なコード
Sub parse()
Dim strPath As String
Dim strPathused As String
'On Error Resume Next
Set objexcel = CreateObject("Excel.Application")
objexcel.Visible = True
objexcel.DisplayAlerts = False
strPath = "C:\prodplan"
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objfso.GetFolder(strPath)
'Loop through objWorkBooks
For Each objfile In objFolder.Files
If objfso.GetExtensionName(objfile.Path) = "xlsx" Then
Set objworkbook = objexcel.Workbooks.Open(objfile.Path)
' Set path for move to at end of script
strPathused = "C:\prodplan\used\" & objworkbook.Name
'open WB to consolidate too
Workbooks.Open "C:\prodplan\compiled\plancon.xlsx"
'Range management sourcebook
Set SRCwb = objworkbook.Worksheets("plan")
Set SRCrange1 = objworkbook.Worksheets("plan").Range("b6:i7")
Set SRCrange2 = objworkbook.Worksheets("plan").Range("k6:p7")
'Set SRCrange3 = objworkbook.Worksheets("").Range("")
'Range management sourcebook
Set DSTwb = Workbooks("plancon.xlsx").Worksheets("data")
'Set DSTrange1 = Workbooks("plancon.xlsx").Worksheets("data").Range("")
'Set DSTrange2 = Workbooks("plancon.xlsx").Worksheets("data").Range("")
'Set DSTrange3 = Workbooks("plancon.xlsx").Worksheets("data").Range("")
'start header dates and shifts copy from objworkbook to consolidated WB
SRCwb.Select
'On Error Resume Next
'SRCwb.Cells.UnMerge
Dim MyColumn As String
Dim Here As String
Dim AC As Variant
'SRCrange1.copy ': This will copy to clipboard
'objworkbook.Worksheets("plan").Range("b6:h7").Select no change from SRCrange1.select
'SRCrange1.Select 'the range does select
'Selection.copy ' this will cause a activecell in DSTwb _
to be copied neither direct reference to SRCrange1.select or .avtivate will change that.
DSTwb.Select
DSTwb.Range("b2").Select
Here = ActiveCell.Address
MyColumn = Mid(Here, InStr(Here, "$") + 1, InStr(2, Here, "$") - 2)
Set lastrow = ActiveWorkbook.ActiveSheet.Range(MyColumn & "65536").End(xlUp).Offset(1, 0)
lastrow.Select
Selection.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipblanks:=False, Transpose:=True
SRCrange2.Select
Selection.copy
Workbooks("plancon.xlsx").Worksheets("sheet1").Select
ActiveSheet.Range("b2").Select
ActiveSheet.Range("b2").Activate
Here = ActiveCell.Address
MyColumn = Mid(Here, InStr(Here, "$") + 1, InStr(2, Here, "$") - 2)
Set lastrow = ActiveWorkbook.ActiveSheet.Range(MyColumn & "65536").End(xlUp).Offset(1, 0)
lastrow.Select
Selection.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipblanks:=False, Transpose:=True
' range3.copy
' Workbooks("data.xlsx").Worksheets("sheet1").Activate
' ActiveSheet.Range("c2").Select
' ActiveSheet.Range("c2").Activate
' Here = ActiveCell.Address
' MyColumn = Mid(Here, InStr(Here, "$") + 1, InStr(2, Here, "$") - 2)
' Set lastrow = ActiveWorkbook.ActiveSheet.Range(MyColumn & "65536").End(xlUp).Offset(1, 0)
' ActiveSheet.Paste Destination:=lastrow
'start loop for objworkbook name copy to field in plancon corisponding with date/shift and copy/paste select row data.
objworkbook.Close False
'Move proccesed file to new Dir
OldFilePath = objfile 'original file location
NewFilePath = strPathused ' new file location
Name OldFilePath As NewFilePath ' move the file
End If
Next
objexcel.Quit
End Sub