Applying background with VBA from worksheet

Cease

Board Regular
Joined
Dec 28, 2010
Messages
112
Hi,
I'm trying to set a background using vba for a file that may be emailed to other machines; and where the background would periodically change based on user selections.

I have been able to change the background from my machine, using:

Rich (BB code):
 ActiveSheet.SetBackgroundPicture Filename:= _
        "\\DTCDAT-VARO050\C_PBO_Users\A763789\My Documents\Images\Star Wars Spacefight.jpg"

I have the image stored as an object within another worksheet that I would like to pull from.
"Sheet17"
it was named Picture 7 but I Changed it to ForcePic


Is there any way to take "Forcepic" from page 17 and set that as the background on another sheet using vba? For this example we can just say Sheet1

I've tried a lot of different options and keep coming up with object undefined errors resulting from my own ignorance with vba.

Any help or direction would be greatly appreciated.

Thank you!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hey,
Maybe it will help showing where I'm stuck.
Code:
Sub newback()
    Dim Pic As Picture
    Windows("Beast PreMacro.xlsm").Activate
    Sheets("Sheet17").Select
    Set Pic = ForcePic
    Windows("Selection of Beast PreMacro xlsm May-16-2011 (2).xlsx").Activate
    Sheets("Sheet1").Select
     ActiveSheet.SetBackgroundPicture Filename:= _
        Pic
End Sub

This stops on the 4th line at 'Set Pic'...
SayingRun-time error '424' Object Required

Any suggestions?

Thank you!
 
Upvote 0
Hey,
I feel like I'm closer:
Code:
Sub newback()
    Dim Pic As Excel.Picture
    Windows("Beast PreMacro.xlsm").Activate
    Set Pic = Worksheets("Picky").Pictures("ForcePic")
    Windows("Selection of Beast PreMacro xlsm May-16-2011 (2).xlsx").Activate
    Sheets("Sheet1").Select
     ActiveSheet.SetBackgroundPicture Filename:= _
        Pic
End Sub
This comes back with Run-time error 13: Type Mismatch, highlighting the last line.

Any idea if there's a way to change the syntax of the SetBackgroundPicture to get this to work?

I know you guys are pretty amazing at this, any ideas, thoughts or advice, please let me know.

Thank you!
 
Upvote 0
Hi everyone,
I'd try this as a new post; but don't want to be that guy.

Can anyone tell me a good place that references how to use pictures in VBA?
Furthermore anyone have any idea if there's a method of the SetBackgroundPicture argument to set the background from a picture that is within a worksheet?

It is a minor thing in the scheme of the workbook I'm building, but it would be a tremendous help to the appearance of it.

Any questions about the sheet or what I'm trying to do, please let me know, I'll be happy to elaborate.

More than that, I'd be greatly thankful for any help advice or direction.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

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