Bunchil
asked on
Image placed on userform lost when file opened on a different computer
Hi all, Nick 97 just helped with this.
I have a spreadsheet with operations perfomed by VBA code on several userforms. I have code that allows a user to select a picture and place it on a user form as image1. The code works properly and users can navigate to a graphic file, select the file and the image is placed on the userfom. With help from Nick97, now each time the userform is initialised the graphic shows on the userform.
Thank works OK while the file is opened on my computer. Can I embed the graphic on the userform so if the file is opened on another computer, (it wont have the correct graphic or file path) the graphic will show on the userform on the new computer.
current routines are:
Bunchil
I have a spreadsheet with operations perfomed by VBA code on several userforms. I have code that allows a user to select a picture and place it on a user form as image1. The code works properly and users can navigate to a graphic file, select the file and the image is placed on the userfom. With help from Nick97, now each time the userform is initialised the graphic shows on the userform.
Thank works OK while the file is opened on my computer. Can I embed the graphic on the userform so if the file is opened on another computer, (it wont have the correct graphic or file path) the graphic will show on the userform on the new computer.
current routines are:
Private Sub CommandButton2_Click()
Dim openDialog As Office.FileDialog
Dim FName As String
Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
openDialog.Filters.Clear
openDialog.Filters.Add "JPEG Files", "*.jpg"
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Select an image file"
.Filters.Add "Image", "*.gif; *.jpg; *.jpeg", 1
If .Show = -1 Then
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
Me.Image1.Picture = LoadPicture(.SelectedItems(1))
Me.Repaint
FName = openDialog.SelectedItems(1)
Sheets("SoftwareParameters").Range("LogoGraphic") = FName
Else
End If
End With
End Sub
Private Sub userForm_Initialize()
Me.Image1.Picture = LoadPicture(Sheets("SoftwareParameters").Range("LogoGraphic"))
End Sub
Bunchil
ASKER
Hi Nick, thanks again it is not a network problem as other computers that will use the file will be in different locations and not networked. Could I save the graphic on a worksheet in the work book and then load it into the userform from there so although they could not see it the graphic used on the userform will be imported onto a hidden worksheet. If that is possible can you advise how to code the importation to a workssheet and then link to a userform please
There's this
http://spreadsheetpage.com/index.php/tip/pasting_an_image_to_a_userform_control/
Your code from before, is that code to permanently set an image on the userform?
Or the image can be changed by the user, but should remain on the form until changed at a later time.
Because I am thinking you wouldn't have bothered to code for a one-and-done,
I think I can get it code to embed in the userform itself -- but I do have to experiment.
Let me know what the whole usage scenario is
http://spreadsheetpage.com/index.php/tip/pasting_an_image_to_a_userform_control/
Your code from before, is that code to permanently set an image on the userform?
Or the image can be changed by the user, but should remain on the form until changed at a later time.
Because I am thinking you wouldn't have bothered to code for a one-and-done,
I think I can get it code to embed in the userform itself -- but I do have to experiment.
Let me know what the whole usage scenario is
ASKER
Hi Nick, checked the link you sent and that works but I don't think the steps that include opening the VBA editor can be coded as VBA code.
The usage scenario is that I have a simple cashflow spreadsheet that people like and it can print summary pages for budgeting purposes. User have asked that they can have their own log placed on the userform for appearance sake. So with some code only accessed by a password, before I send them a copy of the spreadsheet I want to place individual logos on the userform.
I already have code to put the users logo in the header of pages so printed sheet will have the users logo on them.
Individual users will not be able to make any changes - they will be done by me before the spreadsheet is made available.
I look forward to hearing if you are successful with your experimentation
The usage scenario is that I have a simple cashflow spreadsheet that people like and it can print summary pages for budgeting purposes. User have asked that they can have their own log placed on the userform for appearance sake. So with some code only accessed by a password, before I send them a copy of the spreadsheet I want to place individual logos on the userform.
I already have code to put the users logo in the header of pages so printed sheet will have the users logo on them.
Individual users will not be able to make any changes - they will be done by me before the spreadsheet is made available.
I look forward to hearing if you are successful with your experimentation
It can all get coded.
Look here
http://www.oaltd.co.uk/Excel/Default.htm
Now, a lot of that is API code.
That can be hard on the brain.
I do a lot of fun things with images in VBA using the WIA library
https://www.experts-exchange.com/Database/MS_Access/A_13519-Printing-many-large-images-in-MS-Access-reports.html
So, I just need to take your code for selecting an image, combine it with my code for loading the image in WIA with that site's (http://www.oaltd.co.uk/Excel/Default.htm) technique for knocking the clipboard image into the control.
All doable, just kitschy. I'll have a go at it tomorrow.
Look here
http://www.oaltd.co.uk/Excel/Default.htm
Now, a lot of that is API code.
That can be hard on the brain.
I do a lot of fun things with images in VBA using the WIA library
https://www.experts-exchange.com/Database/MS_Access/A_13519-Printing-many-large-images-in-MS-Access-reports.html
So, I just need to take your code for selecting an image, combine it with my code for loading the image in WIA with that site's (http://www.oaltd.co.uk/Excel/Default.htm) technique for knocking the clipboard image into the control.
All doable, just kitschy. I'll have a go at it tomorrow.
Yup,
Take the stuff from the PastePicture.zip from the link here and throw it into a module.
What I did from there is throw a new sheet in, throw the image from .SelectedItems(1) on it, knock that image to the clipboard and hammer it on the userform.
There's a whole module to add too, but the alteration of your code is below.
Sample xls attached
Take the stuff from the PastePicture.zip from the link here and throw it into a module.
What I did from there is throw a new sheet in, throw the image from .SelectedItems(1) on it, knock that image to the clipboard and hammer it on the userform.
There's a whole module to add too, but the alteration of your code is below.
Sample xls attached
Private Sub CommandButton2_Click()
Dim openDialog As Office.FileDialog
Dim SheetName As String
Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
openDialog.Filters.Clear
openDialog.Filters.Add "JPEG Files", "*.jpg"
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Select an image file"
.Filters.Add "Image", "*.gif; *.jpg; *.jpeg", 1
If .Show = -1 Then
'add a sheet
Worksheets.Add
ActiveSheet.Pictures.Insert(.SelectedItems(1)).Select
ActiveSheet.Shapes(1).CopyPicture xlScreen, xlBitmap
SheetName = ActiveSheet.Name
Application.DisplayAlerts = False
Worksheets(SheetName).Delete
Application.DisplayAlerts = True
'Paste the picture from the clipboard into our image control
Me.Image1.Picture = PastePicture(xlBitmap)
Me.Repaint
Else
End If
End With
End Sub
Clipboard.xls
ASKER
Hi Nick Thanks for your help help. I understand what you have explained and have inserted module as suggested but can't get it to work so I downloaded your sample file and that does not appear to work either. I removed code to delete the sheet inserted to take the graphic and it put the graphic on the userform. However if I stop code to look at the userform the graphic disappears again so it is still not embedded in the userform.
Have I made any errors with the code you gave me
Have I made any errors with the code you gave me
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Nick, Thanks again, works perfectly. Have a great Christmas
Bunchil
Bunchil
What you CAN do is take .SelectedItems(1) and use that to save the desired file to a desired network location.
Then the image will work across all the computers on the network.
Do you need help to work out the nuts and bolts of that?
Or do you want to wait and see if someone knows if you can embed the image?