Visual Basic (VB6 and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

Visual Basic Library

This page was last updated on Saturday, November 24, 2001

Public Function boolCellsMerge() As Boolean ' Procedure : boolCellsMerge ' Description: Merge the selected number of cells and move down to select the next number. ' Copyright: Chris Greaves Inc. ' Inputs: None; works only it two or more cells are selected. ' Returns: TRUE if original selection was two or more cells within a table ' Assumes: Nothing ' Side Effects: The current paragraph formatting may change. ' Tested: By the calls below. ' If two or more cells are selected VERTICALLY (one atop the other) ' The cells are merged and the function terminates TRUE. ' If two or more cells are selected HORIZONTALLY ' The cells are merged and the same number of cells in the next row are selected ' and the function terminates TRUE . ' This function is set up to be used as a repetitive macro. To see it work in thise mode, ' Create a table 4x4 cells. Starting at the top-left corner, load a,b,c,d into the first row, ' then continue e,f,g,; i,j,k,l; m,n,o,p until the sixteenth cell is filled. ' Select cells "B" and "C" and call the function. ' Cells "B" and "C" will be merged and Cells "F" and "G" will be selected reday for the next call. ' You could include a "While Selection.Information(wdWithInTable" loop ' and process cells to the end of the table. ' Such a technique is handy when merging city and postcode fields for a set of addresses. boolCellsMerge = False ' Default result is "F"=FAILURE If Selection.Information(wdWithInTable) Then ' we MAY have a job to do Dim intCellsCount As Integer ' How many cells per row to be merged? intCellsCount = Selection.Cells.Count If intCellsCount > 1 Then ' we have a job to do! boolCellsMerge = True Selection.Cells.Merge ' merge just the selected cells in the current row Selection.MoveDown unit:=wdLine, Count:=1 If Selection.Information(wdWithInTable) Then ' continue to the next row Selection.MoveEnd unit:=wdLine, Count:=intCellsCount ' Select the next set of cells Else ' we are done End If Else boolCellsMerge = False ' failure End If Else End If 'Sub TESTboolCellsMerge() ' MsgBox boolCellsMerge 'End Sub End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Monday, November 19, 2001

 

 

Hosted by www.Geocities.ws

1