Need to shell out, open ".jpg" and print to fit page width

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
568
Office Version
  1. 365
Platform
  1. Windows
I realize this is only a start, but I need to be able to shell out and open a file with the name "Test.jpg" and print it out while ensuring that it will print on the width of a single sheet of paper in portrait orientation. I see a lot of code with send keys, but none of that worked for me when I tried it and figured there must be something much simpler to do here. Any help would be much appreciated. Thanks, SS


VBA Code:
Private Sub cmdPrintJobStatus_Click()

VBA.Shell "EXPLORER.EXE \\SomeFolder\PROJECTS\Test.jpg", vbNormalFocus

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Can you bring it into an excel sheet and print it?
 
Upvote 0
I've tried that, but nothing would work so that I could print it in portrait mode and fit the width of the page.
 
Upvote 0
It should be no problem setting the width/height of an inserted picture or shape.
I'll get something in a while when I have a few moments.
 
Upvote 0
Code:
Sub Is_This_A_Start()
With Range("A1")
    ActiveSheet.Shapes.AddPicture("C:\Folder Name Here\Picture Name Including Extension Here", False, True, 0, 0, Columns(10).Left, Rows("46").Top).Name = "Picture 1"
    .Resize(46, 9).PrintOut
End With
End Sub

From VB Help
Shapes.AddPicture Method
Creates a picture from an existing file. Returns a Shape object that represents the new picture.
Syntax
expression.AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)
 
Upvote 0
Another possibility that's easy to change. It maintains the ratio height/width of the original size.
Change references as and where required.
Code:
Sub Another_Way()
Dim sShape As Picture
Set sShape = ActiveSheet.Pictures.Insert("C:\Folder Name Here\Picture Name Including Extension Here")
    With sShape
        .ShapeRange.LockAspectRatio = msoTrue    '<---- Lock the original width/height ratio
        .Left = 0    '<---- Very left of sheet
        .Top = 0    '<---- Very top of sheet
        .Width = Columns(10).Left    '<---- 9 Columns wide
        .Name = "Picture 1"
    End With
ActiveSheet.Range("A1:I47").PrintOut
    'or
    'ActiveSheet.Cells(1, 1).Resize(ActiveSheet.Shapes("Picture 1").BottomRightCell.Row, ActiveSheet.Shapes("Picture 1").BottomRightCell.Column).PrintOut
End Sub
 
Upvote 0
Solution
Going to give it a try right now. Thank you... I'll let you know how this turns out. It looks much cleaner than the stuff I was trying for certain.
 
Upvote 0
Well that was ll I needed to get going again. Below is what I wound up with. I ended up creating a "Temp" worksheet with another macro in order to do everything on from your code and then deleted it. Thanks so much for you help on this.

VBA Code:
Sub AddTempWSCust()
    Dim ws As Worksheet
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    On Error Resume Next
    Set ws = Worksheets("Temp")
    If Err.Number = 9 Then
        Set ws = Worksheets.Add(After:=Sheets(Worksheets.Count))
        ws.Name = "Temp"
        ws.Columns.Width = "2"
        
    Else
        
        Worksheets("Temp").Activate

    End If
    
    With ws
        
        PrintJobStatus4Cust
        
        ws.Shapes("Picture 1").Delete
        
    End With
    
    Worksheets("Temp").Delete
        
    Worksheets("Quick Search Job Status").Activate

    NumLockCorrector
        
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
        
End Sub

and then...

VBA Code:
Sub PrintJobStatus4Cust()
Dim sShape As Picture
Set sShape = Worksheets("Temp").Pictures.Insert("C:\Folder Name Here\Picture Name Including Extension Here")
    
    With sShape
        .ShapeRange.LockAspectRatio = msoTrue    '<---- Lock the original width/height ratio
        .Left = 0   '<---- Very left of sheet
        .Top = 0    '<---- Very top of sheet
        .Width = Columns(24).Left    '<---- 9 Columns wide
        .Name = "Picture 1"
    End With
    
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
        .LeftMargin = Application.CentimetersToPoints(2#)
        .RightMargin = Application.CentimetersToPoints(0.5)
        .TopMargin = Application.CentimetersToPoints(1.5)
        .BottomMargin = Application.CentimetersToPoints(0.5)
        .HeaderMargin = Application.CentimetersToPoints(0.2)
        .FooterMargin = Application.CentimetersToPoints(0.2)
        .PaperSize = xlPaperLetter
        .Orientation = xlPortrait 'xlLandscape
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    
    ActiveSheet.Range("A1:W51").PrintOut
    'ActiveSheet.Range("A1:W32").PrintPreview
    
    'or    'ActiveSheet.Cells(1, 1).Resize(ActiveSheet.Shapes("Picture 1").BottomRightCell.Row, ActiveSheet.Shapes("Picture 1").BottomRightCell.Column).PrintOut

    'or    'ActiveSheet.Cells(1, 1).Resize(ActiveSheet.Shapes("Picture 1").BottomRightCell.Row, ActiveSheet.Shapes("Picture 1").BottomRightCell.Column).PrintPreview

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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