none
VB.NET Programmin with publisher 2003 RRS feed

  • Question

  • I want to Open Publisher document programatically (VB.net 2005) and add page, textbox and some text. Then add new page, text box so on. and How to link textboxes.

    Pl help me

    Chandana De Silva


    Chandana

    Saturday, August 11, 2012 6:21 PM

Answers

  • HiChandana,

    Thank you for posting in the MSDN Forum.

    I've figured out the solution by using the code below.

    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports Publisher = Microsoft.Office.Interop.Publisher
    
    'This is an Console application.
    Namespace ConsoleApplication_Publisher
    	Class Program
    		Private Shared Sub Main(args As String())
    			'Startup Publisher application.
    			Dim myApp As Publisher._Application = New Publisher.Application()
    			'Add a new document.
    			Dim myDoc As Publisher.Document = myApp.Documents.Add()
    
    			'Create a textbox in page 1, and write Hello World! into the textbox.
    			Dim firstPage As Publisher.Page = myDoc.ActiveView.ActivePage
    			Dim textBox As Publisher.Shape = firstPage.Shapes.AddTextbox(Publisher.PbTextOrientation.pbTextOrientationHorizontal, 150, 150, 300, 50)
    			textBox.TextFrame.TextRange.Text = "Hello World!"
    			textBox.TextFrame.TextRange.Font.Size = 36
    
    			'The same goes for the second page.
    			Dim SecondPage As Publisher.Page = myDoc.Pages.Add(1, 1, -1, False)
    			Dim newTextBox As Publisher.Shape = SecondPage.Shapes.AddTextbox(Publisher.PbTextOrientation.pbTextOrientationHorizontal, 150, 150, 300, 50)
    			newTextBox.TextFrame.TextRange.Text = "Hello MSDN!"
    			newTextBox.TextFrame.TextRange.Font.Size = 36
    		End Sub
    	End Class
    End Namespace

    Effect:

    Currently I'm using Win7 & Office 2010, please check whether the code work for you or not. If you still have problems with the code above, please tell me. I'll find a machine with Office 2003 and figure out the solution for you.

    For Publisher reference, please check this page.

    Hope it helps.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 13, 2012 8:55 AM
    Moderator
  • HiChandana,

    The below is what I figured out on a machine with Office 2003.

    Code:

    'This is orginal VB.Net code. The code in my first reply is translated from C#.
    Imports Publisher = Microsoft.Office.Interop.Publisher
    Module Module1
    
        Sub Main()
            Dim myApp As Publisher.Application = New Publisher.Application()
            Dim myDoc As Publisher.Document = myApp.Documents.Add()
    
            Dim firstPage As Publisher.Page = myDoc.ActiveView.ActivePage
            Dim textBox As Publisher.Shape = firstPage.Shapes.AddTextbox(Publisher.PbTextOrientation.pbTextOrientationHorizontal, 150, 150, 300, 50)
            textBox.TextFrame.TextRange.Text = "Hello World!"
            textBox.TextFrame.TextRange.Font.Size = 36
    
            Dim secondPage As Publisher.Page = myDoc.Pages.Add(1, 1, -1, False)
            Dim newTextBox As Publisher.Shape = secondPage.Shapes.AddTextbox(Publisher.PbTextOrientation.pbTextOrientationHorizontal, 150, 150, 300, 50)
            newTextBox.TextFrame.TextRange.Text = "Hello MSDN!"
            newTextBox.TextFrame.TextRange.Font.Size = 36
        End Sub
    
    End Module

    Effect:

    Hope it helps.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 16, 2012 6:22 AM
    Moderator

All replies

  • HiChandana,

    Thank you for posting in the MSDN Forum.

    I've figured out the solution by using the code below.

    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports Publisher = Microsoft.Office.Interop.Publisher
    
    'This is an Console application.
    Namespace ConsoleApplication_Publisher
    	Class Program
    		Private Shared Sub Main(args As String())
    			'Startup Publisher application.
    			Dim myApp As Publisher._Application = New Publisher.Application()
    			'Add a new document.
    			Dim myDoc As Publisher.Document = myApp.Documents.Add()
    
    			'Create a textbox in page 1, and write Hello World! into the textbox.
    			Dim firstPage As Publisher.Page = myDoc.ActiveView.ActivePage
    			Dim textBox As Publisher.Shape = firstPage.Shapes.AddTextbox(Publisher.PbTextOrientation.pbTextOrientationHorizontal, 150, 150, 300, 50)
    			textBox.TextFrame.TextRange.Text = "Hello World!"
    			textBox.TextFrame.TextRange.Font.Size = 36
    
    			'The same goes for the second page.
    			Dim SecondPage As Publisher.Page = myDoc.Pages.Add(1, 1, -1, False)
    			Dim newTextBox As Publisher.Shape = SecondPage.Shapes.AddTextbox(Publisher.PbTextOrientation.pbTextOrientationHorizontal, 150, 150, 300, 50)
    			newTextBox.TextFrame.TextRange.Text = "Hello MSDN!"
    			newTextBox.TextFrame.TextRange.Font.Size = 36
    		End Sub
    	End Class
    End Namespace

    Effect:

    Currently I'm using Win7 & Office 2010, please check whether the code work for you or not. If you still have problems with the code above, please tell me. I'll find a machine with Office 2003 and figure out the solution for you.

    For Publisher reference, please check this page.

    Hope it helps.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 13, 2012 8:55 AM
    Moderator
  • Very nice example. Thank you!


    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Tuesday, August 14, 2012 1:53 AM
  • HiChandana,

    The below is what I figured out on a machine with Office 2003.

    Code:

    'This is orginal VB.Net code. The code in my first reply is translated from C#.
    Imports Publisher = Microsoft.Office.Interop.Publisher
    Module Module1
    
        Sub Main()
            Dim myApp As Publisher.Application = New Publisher.Application()
            Dim myDoc As Publisher.Document = myApp.Documents.Add()
    
            Dim firstPage As Publisher.Page = myDoc.ActiveView.ActivePage
            Dim textBox As Publisher.Shape = firstPage.Shapes.AddTextbox(Publisher.PbTextOrientation.pbTextOrientationHorizontal, 150, 150, 300, 50)
            textBox.TextFrame.TextRange.Text = "Hello World!"
            textBox.TextFrame.TextRange.Font.Size = 36
    
            Dim secondPage As Publisher.Page = myDoc.Pages.Add(1, 1, -1, False)
            Dim newTextBox As Publisher.Shape = secondPage.Shapes.AddTextbox(Publisher.PbTextOrientation.pbTextOrientationHorizontal, 150, 150, 300, 50)
            newTextBox.TextFrame.TextRange.Text = "Hello MSDN!"
            newTextBox.TextFrame.TextRange.Font.Size = 36
        End Sub
    
    End Module

    Effect:

    Hope it helps.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 16, 2012 6:22 AM
    Moderator
  • Lot of Thanks Quist Zhang

    This was helped me,

    How to connection between two textboxes

    Sisil Chandana


    Chandana

    Friday, August 24, 2012 9:47 AM
  • Hi Chandana,

    Sorry, I haven't follow you clearly. What do you mean by connection between two textboxes? Do you mean that once a textbox has been typed into text the other textbox have the same text in it at the same time?

    I think you can open a new thread and describe this requirement more detailed. I'll try to follow your issue.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Saturday, August 25, 2012 2:27 AM
    Moderator