ByteScout BarCode Generator SDK - Microsoft Word - Add Barcode to Word Document in VB.NET - ByteScout

ByteScout BarCode Generator SDK – Microsoft Word – Add Barcode to Word Document in VB.NET

  • Home
  • /
  • Articles
  • /
  • ByteScout BarCode Generator SDK – Microsoft Word – Add Barcode to Word Document in VB.NET

How to add barcode to word document in VB in Microsoft Word using ByteScout Barcode SDK

How to code in Microsoft Word to add barcode to word document in VB with this step-by-step tutorial

The documentation is designed to help you to implement the features on your side. ByteScout Barcode SDK is the robost library (Software Development Kit) that is designed for automatic generation of high-quality barcodes for printing, electronic documents and pdf. All popular barcode types are supported from Code 39 and Code 129 to QR Code, UPC, GS1, GS-128, Datamatrix, PDF417, Maxicode and many others. Provides support for full customization of fonts, colors, output and printing sizes. Special tools are included to verify output quality and printing quality. Can add generated barcode into new or existing documents, images and PDF. It can be used to add barcode to word document in VB using Microsoft Word.

You will save a lot of time on writing and testing code as you may just take the Microsoft Word code from ByteScout Barcode SDK for add barcode to word document in VB below and use it in your application. In your Microsoft Word project or application you may simply copy & paste the code and then run your app! This basic programming language sample code for Microsoft Word will do the whole work for you to add barcode to word document in VB.

ByteScout Barcode SDK free trial version is available on our website. Microsoft Word and other programming languages are supported.

Try it today: Get 60 Day Free Trial or sign up for Web API

InsertIntoMicrosoftWordDocument VB.NET.vbproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>9.0.21022</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{630024F8-F052-4B0B-A87A-5AFD23B4BD3A}</ProjectGuid> <OutputType>Exe</OutputType> <StartupObject>InsertIntoMicrosoftWordDocument_VB.NET.Module1</StartupObject> <RootNamespace>InsertIntoMicrosoftWordDocument_VB.NET</RootNamespace> <AssemblyName>InsertIntoMicrosoftWordDocument VB.NET</AssemblyName> <FileAlignment>512</FileAlignment> <MyType>Console</MyType> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <OptionExplicit>On</OptionExplicit> <OptionCompare>Binary</OptionCompare> <OptionStrict>Off</OptionStrict> <OptionInfer>On</OptionInfer> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <DefineDebug>true</DefineDebug> <DefineTrace>true</DefineTrace> <OutputPath>bin\Debug\</OutputPath> <DocumentationFile>InsertIntoMicrosoftWordDocument VB.NET.xml</DocumentationFile> <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <DefineDebug>false</DefineDebug> <DefineTrace>true</DefineTrace> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DocumentationFile>InsertIntoMicrosoftWordDocument VB.NET.xml</DocumentationFile> <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.BarCode, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Deployment" /> <Reference Include="System.Drawing" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> </ItemGroup> <ItemGroup> <Import Include="Microsoft.VisualBasic" /> <Import Include="System" /> <Import Include="System.Collections" /> <Import Include="System.Collections.Generic" /> <Import Include="System.Data" /> <Import Include="System.Diagnostics" /> </ItemGroup> <ItemGroup> <Compile Include="Module1.vb" /> <Compile Include="My Project\AssemblyInfo.vb" /> <Compile Include="My Project\Application.Designer.vb"> <AutoGen>True</AutoGen> <DependentUpon>Application.myapp</DependentUpon> </Compile> <Compile Include="My Project\Resources.Designer.vb"> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> <DependentUpon>Resources.resx</DependentUpon> </Compile> <Compile Include="My Project\Settings.Designer.vb"> <AutoGen>True</AutoGen> <DependentUpon>Settings.settings</DependentUpon> <DesignTimeSharedInput>True</DesignTimeSharedInput> </Compile> </ItemGroup> <ItemGroup> <EmbeddedResource Include="My Project\Resources.resx"> <Generator>VbMyResourcesResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.vb</LastGenOutput> <CustomToolNamespace>My.Resources</CustomToolNamespace> <SubType>Designer</SubType> </EmbeddedResource> </ItemGroup> <ItemGroup> <None Include="My Project\Application.myapp"> <Generator>MyApplicationCodeGenerator</Generator> <LastGenOutput>Application.Designer.vb</LastGenOutput> </None> <None Include="My Project\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> <CustomToolNamespace>My</CustomToolNamespace> <LastGenOutput>Settings.Designer.vb</LastGenOutput> </None> </ItemGroup> <ItemGroup> <COMReference Include="Microsoft.Office.Core"> <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid> <VersionMajor>2</VersionMajor> <VersionMinor>3</VersionMinor> <Lcid>0</Lcid> <WrapperTool>primary</WrapperTool> <Isolated>False</Isolated> </COMReference> <COMReference Include="VBIDE"> <Guid>{0002E157-0000-0000-C000-000000000046}</Guid> <VersionMajor>5</VersionMajor> <VersionMinor>3</VersionMinor> <Lcid>0</Lcid> <WrapperTool>primary</WrapperTool> <Isolated>False</Isolated> </COMReference> <COMReference Include="Word"> <Guid>{00020905-0000-0000-C000-000000000046}</Guid> <VersionMajor>8</VersionMajor> <VersionMinor>3</VersionMinor> <Lcid>0</Lcid> <WrapperTool>primary</WrapperTool> <Isolated>False</Isolated> </COMReference> </ItemGroup> <ItemGroup> <Content Include="input.doc"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.Targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

Module1.vb
      
' IMPORTANT: ' Copy input.doc to your my documents folder ' and change the path to "input.doc" below ' Word requires to provide absolute path to input files ' ' Imports System Imports System.Collections.Generic Imports System.Drawing Imports System.IO Imports System.Text Imports System.Windows.Forms Imports Bytescout.BarCode Module Module1 <STAThread()> _ Sub Main() ' Create new barcode Dim barcode As New Barcode() ' Set symbology barcode.Symbology = SymbologyType.Codabar ' Set value barcode.Value = "123456" ' Add checksum to barcode barcode.AddChecksum = True ' Create word instance Dim appWord As New Microsoft.Office.Interop.Word.Application() ' Hide word appWord.Visible = False ' Create missing object Dim mis As Object = System.Reflection.Missing.Value ' Template file - change to the appropraite path where you copied input.doc Dim fileInput As Object = "C:\input.doc" ' Template file - change to the appropraite path where you copied input.doc Dim fileOutput As Object = "C:\output.doc" ' Open document Dim docWord As Microsoft.Office.Interop.Word.Document = appWord.Documents.Open(fileInput, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis) ' Set bookmark name Dim bookmarkName As Object = "MyBookmark" ' Get bookmark location Dim bookmarkLocation As Microsoft.Office.Interop.Word.Range = docWord.Bookmarks(bookmarkName).Range() ' Get barcode image Dim image As Bitmap = DirectCast(barcode.GetImage(), Bitmap) ' Copy image to the clipboard Clipboard.SetDataObject(image) ' Paste barcode image to the document bookmarkLocation.Paste() ' Save to the new document docWord.SaveAs(fileOutput, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis, mis) ' We needn't save changes Dim saveChanges As Object = False ' Close word application appWord.Quit(saveChanges, mis, mis) ' Release COM object System.Runtime.InteropServices.Marshal.ReleaseComObject(appWord) End Sub End Module

Try it today: Get 60 Day Free Trial or sign up for Web API

MORE INFORMATION

Get 60 Day Free Trial or Visit ByteScout Barcode SDK page

Explore ByteScout Barcode SDK documentation

WEB API VERSION

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next