Trying To Modify VBA To Repeat This On All Sheets In The Workbook except a few

Jingles3X

New Member
Joined
Oct 20, 2021
Messages
34
Office Version
  1. 2013
Platform
  1. Windows
Hi!
I have the code below, which is working to let me insert a picture in the specified location, but I am trying to have it repeat the process
on all sheets, excluding just a few. I have tried multiple ways to do it, with no success.
Can anyone make a suggestion on how to do this?

VBA Code:
Sub GetPic()
Dim fNameAndPath As Variant
Dim img As Picture         
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
    Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
    With img
       'Resize Picture to fit in the range....
       .Left = ActiveSheet.Range("AC1").Left
       .Top = ActiveSheet.Range("AC1").Top
       .Width = ActiveSheet.Range("AC7:AI7").Width
       .Height = ActiveSheet.Range("AC1:AC7").Height
       .Placement = 1
       .PrintObject = True
       End With

End Sub
 

Jingles3X

New Member
Joined
Oct 20, 2021
Messages
34
Office Version
  1. 2013
Platform
  1. Windows
My mistake, that line should be
VBA Code:
.DrawingObject.PrintObject = True
I seem to be having a different issue now....
The RED line below is giving me a "Type 13", Mismatch error.
I have tried to figure out what's going on, but not successfully.


VBA Code:
Sub Print_Sheets()
Dim I As Long, c As Long
Dim SheetArray() As String

    With ActiveSheet.ListBoxSh

        For I = 0 To .ListCount - 1
            If .Selected(I) Then
                ReDim Preserve SheetArray(c)
                SheetArray(c) = .List(I)
                c = c + 1
            End If
        Next I

        [COLOR=rgb(226, 80, 65)]Sheets(SheetArray()).PrintPreview[/COLOR]
        
        'If you'd like to print out
        'Sheets(SheetArray()).PrintOut

    End With

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
2,598
Office Version
  1. 2013
Platform
  1. Windows
There are a few possible causes for that:
- one of the sheets doesn't exist due to a typo in its name;
- one of the sheets is hidden / very hidden;
- the SheetArray variable contains an Empty element.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,044
Messages
5,767,800
Members
425,437
Latest member
blaix

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
Top