Full Version: Run a word/excel/pp macro from vb 2010 express
UtterAccess Discussion Forums > And More... > Visual Basic 2003 and Later
graemetr
I have found parts of what I need on various different web sites (including this one) but the end result is nothing works and the list of errors gets longer and longer!

First of all I am new to VB and that probably explains most of my problems, secondly I am a copy and paste person which probably explains the rest of my programming problems!

The aim of my little project is to have a database behind a form, take data from a record, open word and paste it into a document, one of the fields contains text that will become the file name of the word document so it needs something to make that happen. Same idea with Excel and powerpoint

After many hours of searching the internet I finally found exactly what I needed and I mean exactly! Copied and pasted it into a new project exactly like it said, made new documents/modules/macros and saved them to the right location. Ran the project and got 28 yes 28 errors! Even I figured out at this stage that there is something significanly wrong here! I checked the 'Applies to' list and no VB 2010! There is a moral here somewhere - read things to the end probably!

Now to my questions -

Will code in vb 2010 Express do what I want in Office 2003, 2007, 2010?

Is my assumption that it easier to do what I want using macros in the Office applications rather than VB 2010 correct? By that I mean paste text into the document and save using info from my database.

So far I have managed to successfully make my database and make a button open a word document from a template but I am stuck on the rest - anybody point me in the right direction?

Graeme
graemetr
I have managed to answer some of my own questions - it appears to be best to use VB to do what i want to do!
But I am stuck now on how to get text from a text control on my database form into a Word 2003 document. This should be a simple and obvious thing to do but I can't manage it and I have spent days googling for the answer

I have managed to open a word document and insert 1234 using:
Dim oRng As Range
Dim ref As String
ref = ("1234")
oRng = oDoc.Bookmarks.Item("\endofdoc").Range
oRng.InsertAfter(ref)
I thought I could replace "1234" with the control name - as that didn't work i am obviously missing the basics (pardon the pun) here!

So my question is how do I get text from a control in the current record in my database to replace "1234" ?
graemetr
The basic thing I was missing was embarrisingly simple - add '.text' after the field name! Now it works!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.