PDA

View Full Version : NEWBIE Q - type mismatch



stecstec
04-11-2006, 03:07 AM
Hi there,

probably a simple solution to this one, keep getting a type mismatch on this code. Is it possible to use a variable within an object collection?

Cheers for any help, Steve.

(I'm trying a subroutine to format a table cell with a variable width and shading percentage.)Public Sub TableCellFormat(ByVal sBookmark As String, _
ByVal sWidth As Integer, _
ByVal sShading As Integer)

Dim sCellWidth As String
Dim sCellShading As String

ActiveDocument.Bookmarks(sBookmark).Select
Selection.SelectCell


' Border width
sCellWidth = "wdLineWidth" & sWidth & "pt"
With Selection.Borders
.OutsideLineWidth = sCellWidth
End With

' Cell shading - yet to do..

End Sub

Killian
04-11-2006, 05:43 AM
When you assign as string to a variable that's declared as an integer, it will be re-cast as a string.
The reason for the type mismatch is you are attempting to set the string you have made, "wdLineWidth" & sWidth & "pt" to the OutsideLineWidth property, which is expecting an integer (from a range of specific values, defined by one of the WdLineWidth constants).

I understand what you were hoping for - refering to one of the constants by name, but it doesn't work that way.

So if you're passing this value in the variable sWidth, you should make sure you have a valid value for OutsideLineWidth (4, 6, 8, 12, 18, 24, 36 or 48) then call the routine and apply it directly.OutsideLineWidth = sWidth

fumei
04-11-2006, 05:44 AM
You are selecting a bookmark but trying to action a table.

Why are you selecting a bookmark????

Killian
04-11-2006, 05:55 AM
Gerry, I guess the bookmark is just a way of referencing a specific cell in the table

fumei
04-12-2006, 12:24 PM
If that is so... ActiveDocument.Bookmarks(sBookmark).Select
Selection.SelectCell are redundant instructions, or somehow different. If the bookmark IS selected. (and it is), why is the Selection selecting cell?

Hmmmm?

If the bookmark is NOT the cell, but only part of it, then a GoTo would be better. If the bookmark IS the cell, the selecting the bookmark does the job, and Selection.Selectcell is redundant.