I am developing with vb.net to print barcode label using Brother Printer PT 98OOPCN. I am using Network Shared, not Peer to Peer.
There is my code
Dim objDoc As bpac.Document
objDoc = CreateObject("bpac.Document")
Dim PrinterName As String = "\\hostprinterserver\printer1"
If (objDoc.Open("Label_Barcode\Label_Ex.lbx")) Then
objDoc.GetObject("dateObject").Text = "10/23/2012"
objDoc.GetObject("barcodeObject").Text = "100123239734"
objDoc.SetPrinter(PrinterName, True)
objDoc.StartPrint("", PrintOptionConstants.bpoDefault)
objDoc.PrintOut(1, PrintOptionConstants.bpoDefault)
objDoc.EndPrint()
objDoc.Close()
End If
Is it possible to print with Brother SDK to Network Shared Printer?
if it is possible how to do that think?
Dim PrinterName As String = "printer1 on hostprinterserver'sIP"
For instance:
Dim PrinterName As String = "Brother PT-9600 on 192.168.1.45"
It worked for me!
Related
I am using a Word dotm file as a template for a SharePoint content type. This word-template contains a Form, opened by a statement in the Document_New() event. A combobox on that form contains the value of a content type property. VBA is used to set the combobox text value via Document.ContentTypeProperties:
Me.cmbComboBox.Text = ThisDocument.ContentTypeProperties("NameOfContentTypeProperty")
This works in Word 2016 on Windows. But in Word 2016 on MacOS this call results in the following error:
Run-time error 5948 This command is not available on this platform.
It seems that this property of the Document object is not available on MacOS.
Does anyone know how to read and write these content type properties in VBA Word 2016 on MacOS?
I managed to read and write the content type properties by editing the XML of the document using the following functions. This works on both Mac and PC.
Function getContentTypeProperty(strElementName As String, docDocument As Word.Document) As String
Dim xmlNode As CustomXMLNode
Dim xmlPart As CustomXMLPart
Set xmlPart = docDocument.CustomXMLParts.SelectByNamespace("http://schemas.microsoft.com/office/2006/metadata/properties").Item(1)
Set xmlNode = xmlPart.SelectSingleNode("/ns0:properties/documentManagement/ns3:" & strElementName)
If xmlNode Is Nothing Then
getContentTypeProperty = ""
Else
getContentTypeProperty = xmlNode.Text
End If
End Function
Function setContentTypeProperty(strElementName As String, docDocument As Word.Document, strValue As String) As Boolean
Dim xmlNode As CustomXMLNode
Dim xmlPart As CustomXMLPart
Set xmlPart = docDocument.CustomXMLParts.SelectByNamespace("http://schemas.microsoft.com/office/2006/metadata/properties").Item(1)
Set xmlNode = xmlPart.SelectSingleNode("/ns0:properties/documentManagement/ns3:" & strElementName)
If xmlNode Is Nothing Then
setContentTypeProperty = False
Else
If getAttributeValueByName(xmlNode.Attributes, "nil") = "true" Then setAttributeValueByName xmlNode.Attributes, "nil", "false"
xmlNode.Text = strValue
setContentTypeProperty = True
End If
End Function
Function getAttributeValueByName(xmlAttributes As CustomXMLNodes, strAttributeName As String) As String
Dim xmlAttribute As CustomXMLNode
Dim strValue As String
For Each xmlAttribute In xmlAttributes
If xmlAttribute.BaseName = strAttributeName Then strValue = xmlAttribute.NodeValue
Next
getAttributeValueByName = strValue
End Function
If the command doesn't exist for Mac you might have to use AppleScript. Unfortunately, I can't help you with AppleScript and I can't find any documentation from MS about what is or isn't available on a Mac.
Here is a compiler directive that will allow you to run different code on Mac or PC.
'Test the conditional compiler constant #Mac
#If Mac Then
'I am a Mac
Me.cmbComboBox.Text = AppleScriptTask ("MyAppleScriptFile.applescript", "myapplescripthandler", "my parameter string")
#Else
'I am Windows
Me.cmbComboBox.Text = ThisDocument.ContentTypeProperties("NameOfContentTypeProperty")
#End If
My client has some internet shortcuts (*.url) on his desktop and I want to get their URL through a VB application and use them as variables.
Any idea how can I do that?
There's a sample on MSDN for *.lnk and *.appref-ms-files.
But seems to work for *.url-files too.
Quote from the site:
To check if a file is a shortcut and to resolve a shortcut path, the
COM Library Microsoft Shell Controls And Automation is used. This
library is added to the References of the Visual Studio project.
Code:
Public Function IsShortcut(strPath As String) As Boolean
If Not File.Exists(strPath) Then
Return False
End If
Dim directory As String = Path.GetDirectoryName(strPath)
Dim strFile As String = Path.GetFileName(strPath)
Dim shell As Shell32.Shell = New Shell32.Shell()
Dim folder As Shell32.Folder = shell.NameSpace(directory)
Dim folderItem As Shell32.FolderItem = folder.ParseName(strFile)
If folderItem IsNot Nothing Then
Return folderItem.IsLink
End If
Return False
End Function
Public Function ResolveShortcut(strPath As String) As String
If IsShortcut(strPath) Then
Dim directory As String = Path.GetDirectoryName(strPath)
Dim strFile As String = Path.GetFileName(strPath)
Dim shell As Shell32.Shell = New Shell32.Shell()
Dim folder As Shell32.Folder = shell.NameSpace(directory)
Dim folderItem As Shell32.FolderItem = folder.ParseName(strFile)
Dim link As Shell32.ShellLinkObject = folderItem.GetLink
Return link.Path
End If
Return String.Empty
End Function
Is there a way to secure the windows mobile so that it will not accept other SD Card Storage except for the one that is registered on that device? I am thinking that it is possible if I can Get the SD Card Serial Number. How to get Serial Number of Memory Card using VB.net Mobile? I can do this in windows-based app but can't find a way in Windows-Mobile... Need help.
For Each drive As DriveInfo In My.Computer.FileSystem.Drives
If drive.IsReady = True AndAlso drive.DriveType = IO.DriveType.Removable Then
Dim fso As Scripting.FileSystemObject
Dim oDrive As Scripting.Drive
fso = CreateObject("Scripting.FileSystemObject")
oDrive = fso.GetDrive(drive.Name)
Dim serialnumber = oDrive.SerialNumber
End if
Next
How can I change settings in my printer (driver), before printing out a PDF?
To be more specific - I want to force my printer driver to use a printer settings instead of driver defaults - basically an equivalent of clicking Properties in a Print window (which opens printer-specific settings), then Advanced Setup and ticking "Use printer settings" checkbox which is by default unticked.
But it could be anything, for example changing dithering mode in a printer.
Here is the functioning code I'm using right now for printing a PDF using my network printer:
Dim PrinterName As String = "\\MyNetwork\ZDesigner ZM400 200 dpi (ZPL)"
Dim WshNetwork = CreateObject("WScript.Network")
WshNetwork.SetDefaultPrinter(PrinterName)
Dim PrintingPageSettings As New Printing.PageSettings()
Me.Text = PrintingPageSettings.PrinterSettings.PrinterName()
Dim isInstalled As Boolean = False
For Each InstalledPrinter As String In Printing.PrinterSettings.InstalledPrinters()
If (PrintingPageSettings.PrinterSettings.PrinterName() = InstalledPrinter.ToString) Then
isInstalled = True
End If
Next
If (isInstalled) Then
AdobeAcrobatCOM.src = Path
AdobeAcrobatCOM.printAll()
Else
Me.Text = PrinterName & " not found"
End If
AdobeAcrobatCOM is AxAcroPDFLib.AxAcroPDF (Adobe PDF Reader from Toolbox, COM components)
Eventually I used TCP connection to the printer and printed it out this way. Here is a code sample:
Dim PrintString As String
Dim ipAddress As String
Dim port As Integer
'123123 is sample integer, "TESTstring" is sample string, Space(2) is sample of adding (two) spaces
PrintString = String.Concat("^XA", "^FO060,080", "^BXN,5,200", "^FD", "TESTstring", 123123, "%^FS", "^FO160,100", "^ACourier,14,14", "^FD", Space(2), "^FS", "^XZ")
ipAddress = "ZDesigner ZM400 200 dpi (ZPL)" 'yes, this works too
port = 9100
'Open Connection
Dim client As New System.Net.Sockets.TcpClient
client.Connect(ipAddress, port)
'Write ZPL String to Connection
Dim writer As New System.IO.StreamWriter(client.GetStream())
writer.Write(PrintString)
writer.Flush()
'Close Connection
writer.Close()
client.Close()
You might want to look for your printer documentation. Here is a C# example for Zebra.
Its 5th Question and apart of one I didn't get response from the experts....
Hope this time I will get the helping hand.
I want to do mailmerge in openoffice using Vb.net and I am totally new with openoffice.
I searched on net for some help to understand how to use openoffice with vb.net but all I get is half info.....So can you please help me and give me code for mailmerge in vb.net for openoffice.
Well i have list of workers in DB and there is this facility that if they want to mail to all or some of the workers then they can do it.I have completed this task using Microsoft Office now as a Add in we are providing the facility to perform the same task using Open Office.
What they have to do is just select the List of workers and click on a button and it will automate the mailmerge using the field of those workers data from DB. The Code of mine is as shown below
Public Sub OpenOfficeMail(ByVal StrFilter As String)
Dim oSM ''Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object ''First objects from the API
Dim arg(-1) ''Ignore it for the moment !
''Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
''Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
''Create a new doc
oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
''Close the doc
oDoc.Close(True)
oDoc = Nothing
''Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///C:\Users\Savan\Documents\1.odt", "_blank", 0, arg)
Dim t_OOo As Type
t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager")
Dim objServiceManager As New Object
objServiceManager = System.Activator.CreateInstance(t_OOo)
Dim oMailMerge As New Object
oMailMerge = t_OOo.InvokeMember("createInstance", Reflection.BindingFlags.InvokeMethod, Nothing, _
objServiceManager, New [Object]() {"com.sun.star.text.MailMerge"}) 'com.sun.star.text.MailMerge"})
oMailMerge.DocumentURL = "file:///C:\Users\Savan\Documents\1.odt"
oMailMerge.DataSourceName = CreateSource(StrFilter)''Function that will return the datasource name which will be a text file's path
oMailMerge.CommandType = 0
oMailMerge.Command = "file:///C:\Mail.txt"
oMailMerge.OutputType = 2
oMailMerge.execute(New [Object]() {})**---->I am getting Error here**
End Sub