Hi,
I am struggling with the below vba code.
I have a worksheet that has attached shapes which are pdf's and this worksheet belongs to a country which is in cell B1 (there are more worksheets for more countries).
The objective of the code is for each shape needs to be copied one by one and pasted into the country folder. I tried selecting all the shapes but these don't paste and I tried with recorded macro which neither works.
I have a problem with the pasting function.
Sub CopyShapesII()
Dim wb As Workbook
Dim sh As Shape
Dim strPath As String
Dim WorkBookPath As String
Dim TargetFile As String
Const RootPath As String = "H:\Works\Extract pdf"
strPath = [b1].Value
'If Dir(RootPath & strPath & "", vbDirectory) <> vbNullString Then
'With Application.FileDialog(msoFileDialogOpen)
'.InitialFileName = RootPath & strPath
'.Show
'End With
'Else
'MsgBox " The path " & RootPath & strPath & " does not exist.", vbExclamation, "Error"
'End If
For Each sh In wb.Worksheets("Invoice Attach").Shapes
If sh.Type = msoPicture Then
wb.Worksheets("Invoice Attach").Shapes(sh.Name).Copy
If Dir(RootPath & strPath & "", vbDirectory) <> vbNullString Then
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = RootPath & strPath
.Show
End With
End If
End If
Next
End Sub
Many thanks,
Dan
I am struggling with the below vba code.
I have a worksheet that has attached shapes which are pdf's and this worksheet belongs to a country which is in cell B1 (there are more worksheets for more countries).
The objective of the code is for each shape needs to be copied one by one and pasted into the country folder. I tried selecting all the shapes but these don't paste and I tried with recorded macro which neither works.
I have a problem with the pasting function.
Sub CopyShapesII()
Dim wb As Workbook
Dim sh As Shape
Dim strPath As String
Dim WorkBookPath As String
Dim TargetFile As String
Const RootPath As String = "H:\Works\Extract pdf"
strPath = [b1].Value
'If Dir(RootPath & strPath & "", vbDirectory) <> vbNullString Then
'With Application.FileDialog(msoFileDialogOpen)
'.InitialFileName = RootPath & strPath
'.Show
'End With
'Else
'MsgBox " The path " & RootPath & strPath & " does not exist.", vbExclamation, "Error"
'End If
For Each sh In wb.Worksheets("Invoice Attach").Shapes
If sh.Type = msoPicture Then
wb.Worksheets("Invoice Attach").Shapes(sh.Name).Copy
If Dir(RootPath & strPath & "", vbDirectory) <> vbNullString Then
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = RootPath & strPath
.Show
End With
End If
End If
Next
End Sub
Many thanks,
Dan