set var to to cell content in word

G

gopher87

Hi all,

I have this subproc in Word:

Sub TranslaMacro()
Dim oTmp As Template
Templates.LoadBuildingBlocks
strName = InputBox(Prompt:="Section?", Title:="AutoTranslate", Default:="")
For Each oTmp In Templates
If oTmp.Name = "Building Blocks.dotx" Then Exit For
Next oTmp
oTmp.BuildingBlockEntries(strName).Insert Selection.Range

End Sub


I have tried to modify it so that varibale strName is automatically set
to the content of the cell in the first column of the word table (same
row of where the cursor is), but had no success.

e.g if cursor is in cell E21 i want the varable to be set to the content
of cell A21.

Any idea on how to do that?

Thanks
 
D

Doug Robbins - Word MVP

The following should do it

Sub TranslaMacro()
Dim oTmp As Template
Dim strName as String
Dim strRange as Range
Templates.LoadBuildingBlocks
Set strRange = Selection.Rows(1).Cells(1).Range
strRange.End = strRange.End -1
strName = strRange.Text
For Each oTmp In Templates
If oTmp.Name = "Building Blocks.dotx" Then Exit For
Next oTmp
oTmp.BuildingBlockEntries(strName).Insert Selection.Range

End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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