0
現在のファイルから別のブックにデータをコピーするVBAスクリプトがあります。手動で実行すると、コードは正常に動作します。現在のワークブックからデータをコピーして別のデータを開き、データを貼り付けて最後に閉じます。Excel 2013 - マクロショートカットは正常に動作しませんが、マクロは手動で有効になります。
ただし、このマクロをショートカットで実行すると、データが貼り付けられ、対象のブックが閉じられません。
Sub CopyToBMD()
'
' CopyToBMD Macro
' Copy Lastest BMD price to appropriate day in the table
'
'
Dim target As Integer
Dim LDate As String
Sheets(1).Select
Range("B48:R48").Copy
LDate = Date
If Cells(40, 2).Value = Cells(1, 2).Value Then
target = 2
Else
target = 8
End If
' Paste data to BMD&CBOT
Dim wbk As Workbook
Dim folderPath As String
Dim ws As Worksheet
'Find file location
folderPath = Application.ActiveWorkbook.Path
FilePath = Dir(folderPath & "\BMD&CBOT.xlsx")
Set wbk = Workbooks.Open(folderPath & "\" & FilePath)
Set ws = wbk.Sheets("CPO-Jun 16")
' i is the row number
Dim i As Integer
For i = 4 To 34
If Cells(i, 1).Value = LDate Then
ws.Cells(i, target).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
Next i
wbk.Close True
End Sub