Results 1 to 11 of 11

Thread: MS Word and Barcode font

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2004
    Posts
    72

    MS Word and Barcode font

    Hi, all

    i have a font problem with a word doc :

    VB Code:
    1. Dim WordObj As Word.Application
    2. Dim WordDoc As Word.Document
    3. Dim WordRange As Word.Range
    4. Dim WordTable As Word.Table
    5. Dim WordColumn As Word.Column
    6. Dim WordRow As Word.Row
    7.  
    8. Private Sub Command1_Click()
    9.  
    10. Set WordObj = Nothing
    11. Set WordObj = CreateObject("Word.Application")
    12. Set WordDoc = WordObj.Documents.Add(DocumentType:=wdNewBlankDocument)   'Open the document
    13. Set WordRange = WordDoc.Range(Start:=0, End:=0)
    14. WordObj.Visible = True
    15.  
    16. With WordRange
    17.     '.Font.Name = "Code 128"
    18.     '.Font.Size = 16
    19.     .InsertParagraphAfter
    20.     .InsertParagraphAfter
    21.     .SetRange Start:=WordRange.End, _
    22.         End:=WordRange.End
    23. End With
    24.  
    25. WordDoc.Range(Start:=0, End:=0).Bold = True
    26. Set WordTable = WordDoc.Tables.Add(WordDoc.Paragraphs.Item(2).Range, 1, 2, wdWord9TableBehavior, wdAutoFitFixed)
    27. Set WordRow = WordTable.Rows.Add(BeforeRow:=WordTable.Rows(1))
    28. Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext
    29. WordDoc.Tables(1).Cell(1, 1).Select
    30. WordRange = Selection.Range
    31.  
    32. ' Adds info to cells
    33.  With WordObj
    34.         ' Prints BC1
    35.         '.ActiveWindow.Selection.Font.Size = 20
    36.         WordRange.Font.Name = "Code 128"
    37.         WordRange.Text = "34324324324332"
    38.         WordRange.Move Unit:=wdCell
    39.        
    40.         WordRange.Font.Name = "Code 128"
    41.         WordRange.Text = "34324324324332"
    42.         WordRange.Move Unit:=wdCell
    43.         'WordTable.Rows.Add BeforeRow:=WordTable.Rows(1)
    44.     End With
    45.        
    46. WordObj.ActiveDocument.SaveAs "C:\BarCode.doc"
    47. 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......

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: MS Word and Barcode font

    Can you upload the font here so I can try the code?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2004
    Posts
    72

    Re: MS Word and Barcode font

    ok np's

    im sure you know where to put it.

    Thanks
    Attached Files Attached Files
    I'm not a pain in the ass, Im just making things intresting......

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: MS Word and Barcode font

    Maybe not. I just tried it. Sorry. Let me work with the code for a minute.

  6. #6
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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:
    1. Option Explicit
    2.    
    3.     Dim WordObj As Word.Application
    4.     Dim WordDoc As Word.Document
    5.     Dim WordRange As Word.Range
    6.     Dim WordTable As Word.Table
    7.     Dim WordColumn As Word.Column
    8.     Dim WordRow As Word.Row
    9.    
    10.     Private Sub Form_Load()
    11.         Set WordObj = Nothing
    12.         Set WordObj = CreateObject("Word.Application")
    13.         Set WordDoc = WordObj.Documents.Add(DocumentType:=wdNewBlankDocument)   'Open the document
    14.         Set WordRange = WordDoc.Range(Start:=0, End:=0)
    15.         WordObj.Visible = True
    16.        
    17.         With WordRange
    18.             '.Font.Name = "Code 128"
    19.             '.Font.Size = 16
    20.             .InsertParagraphAfter
    21.             .InsertParagraphAfter
    22.             .SetRange Start:=WordRange.End, End:=WordRange.End
    23.         End With
    24.        
    25.         WordDoc.Range(Start:=0, End:=0).Bold = True
    26.         Set WordTable = WordDoc.Tables.Add(WordDoc.Paragraphs.Item(2).Range, 1, 2, wdWord9TableBehavior, wdAutoFitFixed)
    27.         Set WordRow = WordTable.Rows.Add(BeforeRow:=WordTable.Rows(1))
    28.         Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext
    29.         WordDoc.Tables(1).Cell(1, 1).Select
    30.         WordRange = Selection.Range
    31.        
    32.         ' Adds info to cells
    33.          With WordObj
    34.                 ' Prints BC1
    35.                 '.ActiveWindow.Selection.Font.Size = 20
    36.                 WordRange.Font.Name = "Code 128"
    37.                 WordRange.Text = "34324324324332"
    38.                 WordRange.Move Unit:=wdCell
    39.                
    40.                 'Set range to cell 1,2
    41.                 WordDoc.Tables(1).Cell(1, 2).Select
    42.                 WordRange = Selection.Range
    43.                
    44.                 WordRange.Font.Name = "Code 128"
    45.                 WordRange.Text = "34324324324332"
    46.                 WordRange.Move Unit:=wdCell
    47.                 'WordTable.Rows.Add BeforeRow:=WordTable.Rows(1)
    48.             End With
    49.                
    50.         WordObj.ActiveDocument.SaveAs "C:\BarCode.doc"
    51.     End Sub

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2004
    Posts
    72

    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......

  8. #8
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: MS Word and Barcode font

    Yes, in both cells.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2004
    Posts
    72

    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:
    1. ' Adds info to cells
    2.             ' Prints BC1
    3.             WordObj.ActiveWindow.Selection.Font.Name = "Code 128"
    4.             'WordRange.Font.Name = "Code 128"
    5.             WordRange.Text = "34324324324332"
    6.             WordRange.Move Unit:=wdCell
    7.            
    8.             'Set range to cell 1,2
    9.             WordDoc.Tables(1).Cell(1, 2).Select
    10.             WordRange = Selection.Range
    11.            
    12.             WordObj.ActiveWindow.Selection.Font.Name = "Code 128"
    13.             'WordRange.Font.Name = "Code 128"
    14.             WordRange.Text = "34324324324332"
    15.             WordRange.Move Unit:=wdCell
    16.             'WordTable.Rows.Add BeforeRow:=WordTable.Rows(1)
    I'm not a pain in the ass, Im just making things intresting......

  10. #10
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: MS Word and Barcode font

    It looks good.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width