473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

VB Macro problem in Word (simple code - I just suck)

Hey all, im getting desperate now.
I have a macro running in Word 2003, when I run the macro it *should* put a 'bottom' cell border in each cell that has the style used - this included a border at the top of the table and one at the bottom, like a set of container border for a table with no border within it. i.e

table heading
_______________________________ << top border
text in the table spanning multiple rows and columns
________________________________<< bottom border

So far, the macro will run, only put the border into a cell that has text!, I cant figure out how to make it go in all cells that have the style, regardless of text.
Also, the very last table in the document end up with all table cells getting the border put in, regardless of style.

This is driving me nuts, im not much of a programmer, but this makes me feel stupid. Can someone plz help me.
Thanks alot!

==========Macro code===========

Sub AfterPublish()

AddCellFormatting "Table border"

End Sub

Private Sub AddCellFormatting(StyleName)
' Searches through the document looking for every
' instance of the style "Table Border" and ensures
' that the borders are turned on for the cells
On Error Resume Next
Dim cellInst As Cell

If Not ActiveDocument.Styles(StyleName).InUse Then
' Gets to here if:
' a) the style exists in the document but is not in use.
' b) the style does not exist in the document.
'Err.Clear
Exit Sub
End If
' Set the selection to the beginning of the document.
Selection.StartOf wdStory
With Selection.Find
' Search direction is forward.
.Forward = True
' Clear any other previous search formatting.
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' Search for the style indicating that the cell should have borders.

.Style = ActiveDocument.Styles(StyleName)

' Search for every instance of this style.
Do While .Execute
' Ensure that the selection is in a table.
If Selection.Information(wdWithInTable) Then
'For each cell within the current selection.
For Each cellInst In Selection.Cells
' Apply custom formatting here:
' To turn off any of these lines, remove or
' prefix with a single quote (') character.

' The following line adds a border around the selected cells...
cellInst.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle


Next
End If
' Move to the next paragraph
Selection.Move wdParagraph, 1
Loop
End With
End Sub
Sep 6 '06 #1
0 2306

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Fazer | last post by:
Here comes another small question from me :-) I am curious as to how I should approach this issue. I would just want to parse simple text and maybe perhaps tables in the future. Would I have to...
0
by: Colin Steadman | last post by:
Apoligies if this post appears twice, but my first attempt at posting it was hours ago and there is still no sign of it in the forum (says five minutes in the confirmation message). ...
10
by: Brian Kwan | last post by:
Requirement: Call a Word Macro from ASP.NET with parameters Do anyone have idea about this? Please notice the import statement and sample code, as I am a beginner using ASP.NET, thanks for your...
3
by: Martin Austin | last post by:
Here's my problem. I'm launching an MS Word object on a Notes document Postopen event. The script kicks off a macro that saves the Word document to a temporary file every n minutes (backup of key...
5
by: Mason | last post by:
I'm having some problems converting VBA for Word 2000 to code that VB.Net understands. I recorded a macro in Word to add numbering (a. b. c.) to my paragraphs. I managed to translate quite a bit...
5
by: Bill | last post by:
This database has no forms. I am viewing an Access table in datasheet view. I'd like to execute a macro to execute a function (using "runcode"). In the function, I'll reading data from the record...
34
by: Umesh | last post by:
how to convert a program to a function/macro and put it in a header file? is there any shortcut method for this? thanks.
0
by: camaro71 | last post by:
Hi there, I really hope someone can help with this one. I have a simple recorded macro (code below) which I'm trying to modify. It's for use in MS Word 2003 tables: With the cursor in front of a...
3
MMcCarthy
by: MMcCarthy | last post by:
Although some users find Macros simple and easy to use, there are some major limitations to using them. Although you can use macros to perform tasks, there is limited control on when and how those...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.