Very experienced Excel and Access but Word newby

A

AltaEgo

I need to understand the VBA module and navigation in Word and programming
differences between Word and (say) Excel . For example

go to start of document
While not end of document
find a table
find a cell in the table
find a line
delete a line
insert a line
insert a row of cells in a table
insert a column of cells in a table
make the table column widths adjust for a new column of cells
etc.


My starting point for a learning project will be:

sub test(chars)

go to start of document
While not end of document
If line starts with chars
Then
whole line delete
Else
next line
End If
Wend
end if

End sub

Sub TableNavigation(chars, rownum)

Find table X
count rows
count columns
Read each cell in rownum
If cell in rownum contains (chars)
Then
check that the cell to the right is not blank
End if

End Sub

Sub TableMath()

Find table Y
Add a row of cells to the bottom
in each row, sum the rows above
End Sub


Can someone point me to a good web reference to get me up and running?
 
T

Tony Jollans

For a learning project, the place to start is the macro recorder.

However, what you propose seems rather arbitrary. As a Word user you must be
aware that a 'line' isn't really a component of a document - just part of
the resuts of mapping a documet to a page; change the page size (or margins
or whatever) and the line changes. Look, instead, at paragraphs, sentences,
words, ranges. Equally, with tables: there are many factors that can affect
column widths and trying to tweak them may drive you quietly crazy; if you
get odd results, try doing the same thing via the UI to see whether it's
really your code that's wrong.
 
A

AltaEgo

It is good to hear that you think my intentions are arbitrary. There's no
point starting on complex concepts with the aim of arriving at the skill to
create a "hello world" message box :)

Part of my initial work will be done copying and pasting from Newsreaders
(note the plural). So, how the problem is solved will depend on how text
formats itself on 'paste'. I am very experienced writing VBA in Excel. I
imagine a lot will be similar in Word. However, as with the differences
experienced when I moved from coding Access to coding Excel, I expect
navigation to be very different. As finding your way around whatever it is
you are working with is critical, I figure this is the place to start.

Perhaps I can solve some navigation problems with F5 and the macro recorder
but, I would like to read over some of the basics first as I did when moving
from learning Access VBA to Excel VBA. Hence my request for a WEB REFERENCE
that includes but is not limited to recognition of location of objects,
beginnings and ends of paragraphs; sentences, documents, sections etc.
 
D

Doug Robbins - Word MVP

Many people who are new to VBA in Word, come unstuck when trying the use a
While not end of document type construction in conjunction with the Find
command.

The way that it should be done is as follows:

Dim frange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="DELETE PAGE", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=True) = True
Selection.Bookmarks("\page").Range.Delete
Loop
End With

In the above case, the OP wanted to delete each page from a document on
which the words DELETE PAGE appeared.

--
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

AltaEgo said:
It is good to hear that you think my intentions are arbitrary. There's no
point starting on complex concepts with the aim of arriving at the skill
to create a "hello world" message box :)

Part of my initial work will be done copying and pasting from Newsreaders
(note the plural). So, how the problem is solved will depend on how text
formats itself on 'paste'. I am very experienced writing VBA in Excel. I
imagine a lot will be similar in Word. However, as with the differences
experienced when I moved from coding Access to coding Excel, I expect
navigation to be very different. As finding your way around whatever it is
you are working with is critical, I figure this is the place to start.

Perhaps I can solve some navigation problems with F5 and the macro
recorder but, I would like to read over some of the basics first as I did
when moving from learning Access VBA to Excel VBA. Hence my request for a
WEB REFERENCE that includes but is not limited to recognition of location
of objects, beginnings and ends of paragraphs; sentences, documents,
sections etc.
 
D

Doug Robbins - Word MVP

Take a look at http://www.mvps.org/ and for Word in particular
http://word.mvps.org/ and http://www.mvps.org/links.html#Word

--
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

AltaEgo said:
Doug

Thank you. This is the type of information I need that doesn't come easy
with the macro recorder.

For anyone following the thread, I found the following in answer to the
original (unanswered) question for a web reference:

http://www.jojo-zawawi.com/code-samples-pages/code-samples.htm

Perhaps someone else has other references?
 

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