KAMACI

Hi,

I made a program with visual basic.I want that people can access my program while writing a word document.In fact i want to make a toolbar for MS Word 2003 and with this toolbar people can able to run my program.

If you help me i will be very happy.
Thanks.



Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

Ji Zhou C MSFT

Hi Cripto,

You can create a Word Add In which adds custom toolbar and button on Word. Then you write the buttons click event handle, in which, you can start your application using the following statement:

System.Diagnostics.Process.Start("C:\Program Files\Your Company\Your Product\Application.exe")

You can refer the following link to see: how to add custom toolbar and button.

http://msdn2.microsoft.com/en-us/library/scff9c7c(VS.80).aspx

Thanks

Ji






Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

KAMACI

Hi,
Firstly thanks for your reply.I read that article.However i couldn't understand something from that article.My problem is that;

Private Sub AddToolbar()

Try
commandBar = Me.CommandBars("Test") 'FIRST
Catch ex As ArgumentException
' Toolbar named Test does not exist so we should create it.
End Try

If commandBar Is Nothing Then
commandBar = Application.CommandBars.Add("Test", 1, False, True) 'SECOND
End If

Try


At the line of FIRST:Itgive me error.Error is: CommandBars is not a member of 'wordAddin1.ThisAddin'.I changed 'Me' keyword and rewrite that line:
commandBar = Application.CommandBars("Test").(When i do this my program runs and don't give me an error while debugging)Is this an appropriate way to solve the problem and for which purpose we use CommandBars method If i make that line a command line (i mean if i write ' commandBar = Application.CommandBars("Test") )
my program runs properly again then why we need to use this method The last thing i want to learn is that: On the SECOND line if commandBar is nothing how we can use "Add" method without "initializing" commandBar.(I am new to Visual Basic and i have to make a project with Visual Basic this questions make seem you not professional but i need help to handle my project.)

If you help me i will be very happy too
Thanks





Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

Ji Zhou C MSFT

KAMACI wrote:
Private Sub AddToolbar()

Try
commandBar = Me.CommandBars("Test") 'FIRST
Catch ex As ArgumentException
' Toolbar named Test does not exist so we should create it.
End Try

If commandBar Is Nothing Then
commandBar = Application.CommandBars.Add("Test", 1, False, True) 'SECOND
End If

Try


At the line of FIRST:Itgive me error.Error is: CommandBars is not a member of 'wordAddin1.ThisAddin'.I changed 'Me' keyword and rewrite that line:
commandBar = Application.CommandBars("Test").(When i do this my program runs and don't give me an error while debugging)Is this an appropriate way to solve the problem and for which purpose we use CommandBars method If i make that line a command line (i mean if i write ' commandBar = Application.CommandBars("Test") )

Yes, that is the appropriate way.

The article on MSDN takes VSTO document-level project as example. Document-level project's root class is ThisDocument, so Me stands for the document. The document has a CommandBars property(same as Application's CommandBars).

You are working with a Word AddIn, the root class is ThisAddIn, so Me stands for the add in's instance, you must use the Application property to access the CommandBars.

Your codes are totally right!

KAMACI wrote:
The last thing i want to learn is that: On the SECOND line if commandBar is nothing how we can use "Add" method without "initializing" commandBar

The above codes first try to get a CommandBar instance named "Test".

If commandBar is nothing, which proves that the "Test" CommandBar is still not created. So we use CommandBars.Add() method to create a CommandBar, and this method returns an instance of newly added CommandBar which we assigned to commandBar variable.

If commandBar is no nothing, which proves there is already a CommandBar named "Test", then we do not need to create it for a second time

Thanks

Ji






Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

KAMACI

Thanks, your comment is my answer.





Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

KAMACI

I have just made a simple toolbar.It has two button and their names are button1 and button2.My problem is that; if a user click button1(or button2), i want to learn the path of which word document the user works on.





Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

Ji Zhou C MSFT

Use this code to get the full Name of the document include its path

MessageBox.Show(this.Application.ActiveDocument.FullName);

Thanks

Ji






Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

KAMACI

This funciton didn't give me the full name of the path.It returns only the document's name, not whole path like (Ex. It returns MyWord instead of C:\Documents and Settings\Myword.doc) Can you help





Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

Ji Zhou C MSFT

Hi Cripto,

It returns the whole path in my machine. ActiveDocument.Name returns the short file name, while ActiveDocument.FullName returns the whole name include the path (Note: only the saved document will return the whole name. I mean, if we create a blank word document and do not save it to any place. It will only return temp name, just like document1, document2)

I copy the following table from the watch window

Code Snippet

Application.ActiveDocument.Name "Doc2.docx" string

Application.ActiveDocument.FullName "C:\\Documents and Settings\\v-jzho\\My Documents\\Doc2.docx" string

If this still does not help. I want to make sure our Office Version. I test in Office 2007

Thanks

Ji






Re: Visual Studio Tools for Office A Toolbar for MS Word 2003

KAMACI

Probably i didn't save my document and tried it .It works now on Ms Word 2003 .Thanks again.