MsgBox Print

ra_weiss

New Member
Joined
Oct 18, 2008
Messages
35
Oh, me-oh-my, what have I screwed up this time?

Code:
Dim MyFile As String


MsgResult = MsgBox("BOOM! You're done. Print Copies?", vbYesNo, "")
If MsgResult = vbYes Then
MyFile = Dir("C:\Documents and Settings\*i*.xls")
Do While MyFile <> ""
    Worksheet.PrintOut Filename:=MyFile ActivePrinter:="Canon MX320 series Printer"
    MyFile = Dir()
Loop
Else: End If

Why is "Worksheet.PrintOut Filename:=MyFile ActivePrinter:="Canon MX320 series Printer" rejected? Thanks.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hey, Norie. What do you mean, what is worksheet?

BTW, I applied your sumif suggestion yesterday. Along with a few conditional formats it wrks like a dream!
 
Upvote 0
Well what is it?

A variable?

Is it supposed to be a reference to something? Perhaps the workbooks you aren't opening?:)
 
Upvote 0
Assuming the code is meant to find files with name that matches a pattern (*i*) and extension (xls), open them and then print them:
Code:
Option Explicit
 
Sub Printer()
Dim wbOpen As Workbook
Dim MyFile As String
 
    MsgResult = MsgBox("BOOM! You're done. Print Copies?", vbYesNo, "")
 
    If MsgResult = vbYes Then
 
        MyFile = Dir("C:\Documents and Settings\*i*.xls")
 
        Do While MyFile <> ""
 
            Set wbOpen = Workbooks.Open(MyFile)
 
            wbOpen.Worksheets.PrintOut ActivePrinter:="Canon MX320 series Printer"
 
            wbOpen.Close SaveChanges:=False
 
            MyFile = Dir()
 
        Loop
 
    End If
 
End Sub
Note this is a big guess, and I can't really test it because my wireless printer isn't particularly good at being wireless.:eek:
 
Upvote 0
You're close. Actually, this dumb print command is at the back end of another sub already, one which just calculated the 2 workbooks I want printed. But for the life of me, I can't get focus on them or put them in a variable.

You have to excuse me, I'm picking this stuff back up again after not touching it for many years. I'm guessing it will take you -2 seconds to get these two workbooks printed via msgbox.

Code:
    ActiveWorkbook.SaveAs "C:\Documents and Settings\" & Format(Now(), "mm-dd-yyyy") & " Invoice ", FileFormat:=56
        ActiveWorkbook.Close savechanges:=True
    ActiveWorkbook.SaveAs "C:\Documents and Settings\" & Format(Now(), "mm-dd-yyyy") & " Equipment Sheet ", FileFormat:=56
        ActiveWorkbook.Close savechanges:=True

Let MyFile = Dir("C:\Documents and Settings\*i*.xls")

MsgResult = MsgBox("BOOM! You're done. Print Copies?", vbYesNo)
If MsgResult = vbYes Then
    Do While MyFile <> ""
    Worksheets.PrintOut , MyFile, ActivePrinter:="Canon MX320 series Printer"
    MyFile = Dir()
Loop
Else: End If
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,734
Members
452,939
Latest member
WCrawford

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