Error in code to save loaded pictures in userform to specific path

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63
Hello, I have the following code that I got with the help of this wonderful forum. I have modified a little but it is not working. Would it be possible to get your help?
Code:
Private Sub PicToSheet1(picControl, sht As Worksheet)
    Dim PCAR As String
    CAR = Me.TextBox1.Value
    Dim p As String, L As Double, T As Double, H As Double
    path = "C:\Users\Anahi\Desktop\PCAR Project\Folders" & CAR
    
'save temporary image to folder
    SavePicture picControl.Picture, path
'embed image in sheet
    L = sht.Cells(13, 1).Left: T = sht.Cells(13, 1).Top
    With sht.Shapes.AddPicture(Filename:=p, linktofile:=msoFalse, savewithdocument:=msoCTrue, Left:=L, Top:=T, Width:=290, Height:=220)
        .Placement = xlMove
        .OLEFormat.Object.PrintObject = msoTrue
        .OLEFormat.Object.Locked = msoTrue
    End With
'delete temporary file
   
End Sub

When I run the above code, it gives me error in this line: SavePicture picControl.Picture, path. I would like the picture loaded in userfomer1 Image1 saved with that name and Image 2 saved with that name as well in the path that depends on CAR #. Can you help me please?
 
Last edited by a moderator:
In the line below
Code:
path = ...
insert this line
Code:
Debug.Print path
which prints the string to the immediate window
View the immediate window in VBA editor with {CTRL} G

The error is in that string
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You said you got an error. What, and where, is it?
 
Upvote 0

Forum statistics

Threads
1,215,794
Messages
6,126,945
Members
449,349
Latest member
Omer Lutfu Neziroglu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top