VBA to Select .PNG Files to Print out

michele227

New Member
Joined
Feb 15, 2023
Messages
15
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone!

I am currently trying to put together a VBA to open a file dialogue, select PNG files, have a window come up to select the printer, and then print them out with the selected printer.
Everything works, except the printing out part!
I would really appreciate any guidance! :)

This is what I have so far:

Sub PrintOutSketches2()

Dim selectedfiles As String
Dim xApp As Object
Dim xFileDlg As FileDialog
Dim xSelItem As Variant
On Error Resume Next
Set xApp = CreateObject("Excel.Application")
xApp.Visible = False


Set xFileDlg = Application.FileDialog(msoFileDialogFilePicker)
xFileDlg.InitialFileName = Sheets("Payment Schedule").Range("O17").Value
xFileDlg.AllowMultiSelect = True
xFileDlg.Filters.Add "PNG", "*.png"
xFileDlg.Title = "Select Drawings"

If xFileDlg.Show <> 0 Then
selectedfiles = xFileDlg.SelectedItems(1)

x = Application.Dialogs(xlDialogPrinterSetup).Show
Debug.Print

End If

Sheets("Payment Schedule").Select

End Sub

Thank you in advance!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try this:
Application.Dialogs(xlDialogPrint).Show
 
Upvote 0
Try this:
Application.Dialogs(xlDialogPrint).Show
Thank you for your response!

I made this change, but it printed the first sheet in my workbook, and not the selected images from the File Dialogue.
 
Upvote 0
Hard to test without the file. Sorry. Maybe this will work?
selectedFiles.Printout Copies:=1
 
Upvote 0
Hard to test without the file. Sorry. Maybe this will work?
selectedFiles.Printout Copies:=1
Thank you, I just tried it but no luck.
Says selectedfiles is invalid.
I tried xselitems and it didn’t work either.

Not sure what to do ☹️
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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