Print code on userform

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
The working code supplied below is what i use to view a saved invoice.
What i am looking for is to now use the same code but with an edit.
Once the button is pressed it will look for the invoice number & print it as opposed to viewing it.
Thanks



Code:
Private Sub OpenInvoice_Click()

    Const FILE_PATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\"
    
    If txtInvoiceNumber = "N/A" Or Len(txtInvoiceNumber) = 0 Then
                MsgBox "Invoice N/A For This Customer", vbExclamation, "N/A INVOICE NOTICE"
    Else
        If Len(Dir(FILE_PATH & txtInvoiceNumber.Value & ".pdf")) = 0 Then
            If MsgBox("Would You Like To Open The Folder ?", vbCritical + vbYesNo, "Warning Invoice is Missing.") = vbYes Then
                CreateObject("Shell.Application").Open ("C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\")
            End If
        Else
            CreateObject("Shell.Application").Open (FILE_PATH & txtInvoiceNumber.Value & ".pdf")
        End If
    End If
End Sub
 
Hi,
Pressing print after customer has been selected shows me the pdf invoice.
I then see a Run Time Error of,
2147217375 (80041021)

Pressing Debug shows me this in yellow.

Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & sComputer & "\root\cimv2")
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
@ipbr21054

Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & sComputer & "\root\cimv2")

Where are the anti-slashes "" ?

Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2
 
Last edited:
Upvote 0
I copied the code from post #10 & now looking at that post 1 x / is missing,see below.

Now with the extra \ added to the code after the print has finished the Adobe shutsdown etc by itself & thus works.

See post 10 code below
Code:
[COLOR=#333333]Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}![/COLOR][COLOR=#ff0000]\[/COLOR][COLOR=#333333]" & sComputer & "\root\cimv2")[/COLOR]

Many thanks for your time & help.

Cheers
 
Upvote 0

Forum statistics

Threads
1,215,232
Messages
6,123,759
Members
449,120
Latest member
Aa2

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