Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim Pr As Printer
Dim myUSBPrinter As Printer
For Each Pr In Printers
If Instr ( Pr.Port, "USB" ) > 0 Then
[COLOR=Green]' Found a USB Printer[/color]
Set myUSBPrinter = Pr
Exit For
End If
Next Pr
If myUSBPrinter Is Nothing Then
Msgbox "No USB Printer Found"
Else
[COLOR=Green]' Now you can print to myUSBPrinter[/Color]
Dim OldDefaultPrinter As String
OldDefaultPrinter = SetPrinterAsDefault( myUSBPrinter.DeviceName )
myUSBPrinter.Print "This is a String to Print"
myUSBPrinter.EndDoc
SetPrinterAsDefault( OldDefaultPrinter )
End If
Public Function SetPrinterAsDefault(ByVal NewDefault As String) As String
Dim nC As Integer
Dim String_Len As Long
Dim strWinPath As String
Dim strSysFileName As String
Dim strRet As String
Dim Current_Default As String
Dim New_Printer As String
Dim Pr As Printer
[COLOR=green]' Windows wants "Device Name,Driver Name,Port" in the string to set
' a new default printer.[/color]
New_Printer = ""
For Each Pr In Printers
If Pr.DeviceName = NewDefault Then
New_Printer = Pr.DeviceName & "," & Pr.DriverName & "," & Pr.Port
Exit For
End If
Next
[COLOR=green]' Get the path of the Windows\System directory.[/color]
strWinPath = Space$(MAX_FILENAME_LEN)
String_Len = GetWindowsDirectory(strWinPath, 256)
strWinPath = Left$(strWinPath, String_Len)
strSysFileName = strWinPath & "\win.ini"
[COLOR=green]' Get the current default printer
' This will be of the form 'DeviceName,DriverName,Port'
' For example "iDP3210 Full Cut,iDP3210,LPT1:"[/color]
strRet = Space$(256)
String_Len = GetPrivateProfileString("windows", "device", "", strRet, 256, strSysFileName)
Current_Default = Left$(strRet, String_Len)
[COLOR=green]' If he didn't provide a new printer name then just return the current default.[/color]
If Len(New_Printer) = 0 Then
nC = InStr(1, Current_Default, ",")
If nC = 0 Then nC = Len(Current_Default) + 1
SetPrinterAsDefault = Left$(Current_Default, nC - 1)
End If
End Function
Public Declare Function GetWindowsDirectory Lib "kernel32" _
Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpSectionName As String, _
ByVal lpKeyName As Any, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpSectionName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) As Long
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long