Sep 22nd, 2005, 08:23 PM
#1
Thread Starter
Lively Member
MS Word and Barcode font
Hi, all
i have a font problem with a word doc :
VB Code:
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Dim WordTable As Word.Table
Dim WordColumn As Word.Column
Dim WordRow As Word.Row
Private Sub Command1_Click()
Set WordObj = Nothing
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Add(DocumentType:=wdNewBlankDocument) 'Open the document
Set WordRange = WordDoc.Range(Start:=0, End:=0)
WordObj.Visible = True
With WordRange
'.Font.Name = "Code 128"
'.Font.Size = 16
.InsertParagraphAfter
.InsertParagraphAfter
.SetRange Start:=WordRange.End, _
End:=WordRange.End
End With
WordDoc.Range(Start:=0, End:=0).Bold = True
Set WordTable = WordDoc.Tables.Add(WordDoc.Paragraphs.Item(2).Range, 1, 2, wdWord9TableBehavior, wdAutoFitFixed)
Set WordRow = WordTable.Rows.Add(BeforeRow:=WordTable.Rows(1))
Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext
WordDoc.Tables(1).Cell(1, 1).Select
WordRange = Selection.Range
' Adds info to cells
With WordObj
' Prints BC1
'.ActiveWindow.Selection.Font.Size = 20
WordRange.Font.Name = "Code 128"
WordRange.Text = "34324324324332"
WordRange.Move Unit:=wdCell
WordRange.Font.Name = "Code 128"
WordRange.Text = "34324324324332"
WordRange.Move Unit:=wdCell
'WordTable.Rows.Add BeforeRow:=WordTable.Rows(1)
End With
WordObj.ActiveDocument.SaveAs "C:\BarCode.doc"
End Sub
when run it creates the word doc, saves it all fine but it doesnt print out in "Code 128" Font, Ive installed it in the font folder, and if i open word app manually and use it it prints fine, but when i run the code it just prints out in "New Roman" or something
ive looked around msdn and google but nothing really
would anyone know why the font wont shift to code 128?
Thanks
I'm not a pain in the ass, Im just making things intresting......
Sep 22nd, 2005, 08:27 PM
#2
Re: MS Word and Barcode font
Can you upload the font here so I can try the code?
Sep 22nd, 2005, 08:32 PM
#3
Thread Starter
Lively Member
Re: MS Word and Barcode font
ok np's
im sure you know where to put it.
Thanks
Attached Files
I'm not a pain in the ass, Im just making things intresting......
Sep 22nd, 2005, 08:48 PM
#4
Re: MS Word and Barcode font
This line is your problem
WordDoc.Tables(1).Cell(1, 1).Select
You are setting the range to be only the first cell of the table.
Sep 22nd, 2005, 08:49 PM
#5
Re: MS Word and Barcode font
Maybe not. I just tried it. Sorry. Let me work with the code for a minute.
Sep 22nd, 2005, 08:55 PM
#6
Re: MS Word and Barcode font
Actually it is. Try this code. With it, you will get the bar code in both table cells:
VB Code:
Option Explicit
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Dim WordTable As Word.Table
Dim WordColumn As Word.Column
Dim WordRow As Word.Row
Private Sub Form_Load()
Set WordObj = Nothing
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Add(DocumentType:=wdNewBlankDocument) 'Open the document
Set WordRange = WordDoc.Range(Start:=0, End:=0)
WordObj.Visible = True
With WordRange
'.Font.Name = "Code 128"
'.Font.Size = 16
.InsertParagraphAfter
.InsertParagraphAfter
.SetRange Start:=WordRange.End, End:=WordRange.End
End With
WordDoc.Range(Start:=0, End:=0).Bold = True
Set WordTable = WordDoc.Tables.Add(WordDoc.Paragraphs.Item(2).Range, 1, 2, wdWord9TableBehavior, wdAutoFitFixed)
Set WordRow = WordTable.Rows.Add(BeforeRow:=WordTable.Rows(1))
Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext
WordDoc.Tables(1).Cell(1, 1).Select
WordRange = Selection.Range
' Adds info to cells
With WordObj
' Prints BC1
'.ActiveWindow.Selection.Font.Size = 20
WordRange.Font.Name = "Code 128"
WordRange.Text = "34324324324332"
WordRange.Move Unit:=wdCell
'Set range to cell 1,2
WordDoc.Tables(1).Cell(1, 2).Select
WordRange = Selection.Range
WordRange.Font.Name = "Code 128"
WordRange.Text = "34324324324332"
WordRange.Move Unit:=wdCell
'WordTable.Rows.Add BeforeRow:=WordTable.Rows(1)
End With
WordObj.ActiveDocument.SaveAs "C:\BarCode.doc"
End Sub
Sep 22nd, 2005, 09:41 PM
#7
Thread Starter
Lively Member
Re: MS Word and Barcode font
you know what? for for reason it still pints new times roman.
did print the numbers in barcode font to you?
I'm not a pain in the ass, Im just making things intresting......
Sep 22nd, 2005, 09:45 PM
#8
Re: MS Word and Barcode font
Sep 22nd, 2005, 09:51 PM
#9
Thread Starter
Lively Member
Re: MS Word and Barcode font
ok i got it working but it feels a little unstable to me. this what i did
VB Code:
' Adds info to cells
' Prints BC1
WordObj.ActiveWindow.Selection.Font.Name = "Code 128"
'WordRange.Font.Name = "Code 128"
WordRange.Text = "34324324324332"
WordRange.Move Unit:=wdCell
'Set range to cell 1,2
WordDoc.Tables(1).Cell(1, 2).Select
WordRange = Selection.Range
WordObj.ActiveWindow.Selection.Font.Name = "Code 128"
'WordRange.Font.Name = "Code 128"
WordRange.Text = "34324324324332"
WordRange.Move Unit:=wdCell
'WordTable.Rows.Add BeforeRow:=WordTable.Rows(1)
I'm not a pain in the ass, Im just making things intresting......
Sep 22nd, 2005, 10:08 PM
#10
Re: MS Word and Barcode font
Sep 22nd, 2005, 10:10 PM
#11
Re: MS Word and Barcode font
Moved from Classic VB
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width