How to run VBA code from VB.Net

K

Kim Helmer

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
 
C

Cor Ligthert

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
 
H

Herfried K. Wagner [MVP]

* "Kim Helmer said:
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.
 

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