MS Word To OneNote

A

Al Borges

Hi Folks:

After my earlier question went dead with nobody being able to figure out at
least one method of getting information from Word to OneNote, and after
seeing the same in chat rooms going back to 2004, I spent the past few days
figuring out 2 methods. So far, one works pretty well.

METHOD 1
-------------

1) copy a phrase, s.a. "SOAP NOTE 6/29/2005", then run the following code in
a clickbutton; this will be your TITLE.
2) Here's the code:

' bring up OneNote document and add in a new page
strpath = "c:\program files\microsoft office\office11\onenote.exe"
strswitch = " /new C:\onenoteimport.one"
strcmd = strpath & strswitch
Shell strcmd, vbMaximizedFocus

'paste in your TITLE phrase "SOAP NOTE 6/29/2005"
strswitch = " /paste"
strcmd = strpath & strswitch
Shell strcmd, vbMaximizedFocus

'TAB out of the TITLE field
SendKeys "%{TAB}", True

'copy your current Word document contents
Application.Selection.SetRange Start:=Selection.Start,
End:=ActiveDocument.Content.End
Application.Selection.Copy

'paste it
strswitch = " /paste"
strcmd = strpath & strswitch
Shell strcmd, vbMaximizedFocus

--------------------------------------------------------------------

METHOD 2
-------------

I'll be working on the CSimpleImporterClass method to do the same. It
supposedly offers more control, but it's tricky. I have yet to see anyone
really work with it outside of one Excel project that I found on the 'net
(http://www.mrexcel.com/tip078.shtml). I did find that one poster back in
December started to programmatically control OneNote through this method
(http://theofficeexperts.com/forum/showthread.php?t=3786). Here is his code,
but still no go since it breaks on the "brigitte":

--------------

Dim objOneNote As OneNote.CSimpleImporter

Set objOneNote = New OneNote.CSimpleImporter
'the folder name is "Cabinet"
'the page name is " brigitte " =>the third one on the list (3-brigitte )
' onenote 2003 sp1 show up with an error message
' the debugger stops on the next line

objOneNote.NavigateToPage "Cabinet.one", "brigitte"
End Sub
anyone can provide the right code

purpose is to navigate only ( display a specified page )

----------------

One error that I see is that instead of using the title "brigitte" you need
to put in a GUID expression. I tried rewriting the thing using an automatic
GUID generator (http://www.trigeminal.com/code/guids.bas), but it seems that
you need to use the actual OneNote active GUID pagenumber, including the one
given automatically to new pages. Anyone know how to get that?

Gosh, I'd like to break this code...

Thanks,
Al
 
F

Fritz Switzer

Dr. Al,

wrt Method 2:
I have yet to see anyone really work with it outside of one Excel project
that I found on the 'net

The ImporterClass is the basis for our OneNote Toolkits. We use it
extensively to import data into OneNote. We import data from: 1. Access
DataBases
2. ISF (Ink Serialized Format)
3. Graphic Objects
4. Windows Forms Applications
5. Web Services

IIRC, the issue with GUIDs is you can't currently get the GUID for a note,
but if you generate your own and keep track of it somewhere you can go back
and modify the page using the GUID. Because our charting solution creates a
longitudinal Patient Chart, we just "append" a new note as part of the
patient record, consequently no GUID management is required. We just let
OneNote create it.

I'll take a look at the Word Object Model and post some code on the
Developer FAQ page on my website. (It will be in C# though :) )

Fritz
 
F

Fritz Switzer

Dr. Al,

Here is the simplest example of adding content to OneNote I could come up
with. Add a reference to your Importer DLL and note there is an ambiguity
reference to Application. The complete app is on the Developer FAQ at my
website (C#)

using Microsoft.Office.OneNote;

static void Main()
{
//Application.Run(new Form1());
System.Windows.Forms.Application.Run(new Form1());

}

private void button1_Click(object sender, System.EventArgs e)
{

Page p = new Page("General.one","Import Test");
OutlineObject outline = new OutlineObject();
outline.AddContent(new HtmlContent("Hello OneNote! "));
p.AddObject(outline);

p.Commit();
p.NavigateTo();


}


Hope this helps,

Fritz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top