By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

How to run VBA code from VB.Net

P: n/a
I have made a macro that works fine in Word, but when I paste it into a
VB.net project some of the code appears as 'not declared'. The code that
shows not declared is activedocument, wdCollapseEnd and wdCollapseEnd.

What reference/import am I missing.

All help appreciated.

----
imports Word
imports Microsoft.Office.Core
---
Sub kims()
Dim wordDocument As Word.Document
Dim tableRange As Word.Range
Dim pictureRange As Word.Range
Dim pictureTable As Word.Table
Dim feltet As Word.Field

Set wordDocument = ActiveDocument

wordDocument.Paragraphs.Add
Set tableRange = wordDocument.Paragraphs.Last.Range
Set pictureTable = wordDocument.Tables.Add(tableRange, 1, 1)
Set pictureRange = pictureTable.Cell(1, 1).Range
pictureTable.Columns.Item(1).Width = 120
pictureTable.Rows.Item(1).Height = 120

Dim picture As String
picture = "c:\\test.jpg"

Set pictureRange = ActiveDocument.Content
pictureRange.Collapse Direction:=wdCollapseEnd

pictureRange.Fields.Add pictureRange, Type:=wdFieldEmpty,
Text:="INCLUDEPICTURE """ & picture & """" _
, PreserveFormatting:=False
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Kim,

In VBNet all variables have to be declared, so how should VBNet know what is
wdCollapseEnd, for VBNet it are only 13 characters when it does not know
what it is

I hope this give an idea?

Cor
Nov 21 '05 #2

P: n/a
* "Kim Helmer" <ki*******@no-email.dk> scripsit:
I have made a macro that works fine in Word, but when I paste it into a
VB.net project some of the code appears as 'not declared'. The code that
shows not declared is activedocument, wdCollapseEnd and wdCollapseEnd.


Start the object browser and search for the constant, then import the
class/enum that contains this constant or fully qualify it.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.