Hide Gridlines

  • Thread starter tiki99 via OfficeKB.com
  • Start date
T

tiki99 via OfficeKB.com

Using vb.net, how do you programmatically hide/show the gridlines of a table
in a word document? The table and the document were also created via vb.net.

Thanks
Bob
 
D

Doug Robbins - Word MVP

The command to use is

WordBasic.ShowTableGridlines

It toggles the display of the Gridlines.

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

tiki99 via OfficeKB.com

Thanks for your reply. Would anyone know how to convert that to vba? I used:

oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("c:\worddoc.doc")

Thanks for your help,
Bob
 
P

Peter Jamieson

I think the following would probably work:

Private oWB As Object

oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("c:\worddoc.doc")
oWB = oWord.WordBasic
oWB.ShowTableGridlines()


Peter Jamieson

http://tips.pjmsn.me.uk
Thanks for your reply. Would anyone know how to convert that to vba? I used:

oWord = CreateObject("Word.Application")
 
T

tiki99 via OfficeKB.com

Thanks for your help Peter. I placed the 'Private oWB As Object' in the Class
area and the

oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("c:\worddoc.doc")
oWB = oWord.WordBasic
oWB.ShowTableGridlines()

in a button_click procedure.

I received an "Unhandled Exception" that said:
Object reference not set to an instance of an object.
Use the "new" keyword to create an object instance.

It seems like it should work. Any suggestions?

Thanks,
Bob


Peter said:
I think the following would probably work:

Private oWB As Object

oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("c:\worddoc.doc")
oWB = oWord.WordBasic
oWB.ShowTableGridlines()

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks for your reply. Would anyone know how to convert that to vba? I used:

oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("c:\worddoc.doc")
[quoted text clipped - 16 lines]
 
P

Peter Jamieson

Well, my very simple test routine just does

Imports Microsoft.Office.Interop

Module Module1
Private oWord As Word.Application
Private oDoc As Word.Document
Private oWB As Object
Sub main()
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Open("c:\a\noborders.docx")
oWB = oWord.WordBasic
oWB.showtablegridlines()
End Sub

End Module

Does that give you any clues?

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks for your help Peter. I placed the 'Private oWB As Object' in the Class
area and the

oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("c:\worddoc.doc")
oWB = oWord.WordBasic
oWB.ShowTableGridlines()

in a button_click procedure.

I received an "Unhandled Exception" that said:
Object reference not set to an instance of an object.
Use the "new" keyword to create an object instance.

It seems like it should work. Any suggestions?

Thanks,
Bob


Peter said:
I think the following would probably work:

Private oWB As Object

oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("c:\worddoc.doc")
oWB = oWord.WordBasic
oWB.ShowTableGridlines()

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks for your reply. Would anyone know how to convert that to vba? I used:
oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("c:\worddoc.doc")
[quoted text clipped - 16 lines]
Thanks
Bob
 
T

tiki99 via OfficeKB.com

Thanks Peter. I appreciate your help. You'll have to be patient as I'm a
novice. I'm using the vb.net express 2008 platform. The OS is Vista. I have a
MS Office 10.0 library reference and I'm using Word 2002. I've added the
namespace in module1: Imports Microsoft.Office.Interop. The namespace is also
checked on the project page. I copied and pasted your code into the sub main.
I changed to my document and then started the debugger. The document opened
fine but I then received this unhandled exception:

Public member 'showtablegridlines' on type '_ComObject' not found.

Now i'm reallly confused.

Thanks,
Bob


Peter said:
Well, my very simple test routine just does

Imports Microsoft.Office.Interop

Module Module1
Private oWord As Word.Application
Private oDoc As Word.Document
Private oWB As Object
Sub main()
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Open("c:\a\noborders.docx")
oWB = oWord.WordBasic
oWB.showtablegridlines()
End Sub

End Module

Does that give you any clues?

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks for your help Peter. I placed the 'Private oWB As Object' in the Class
area and the
[quoted text clipped - 37 lines]
 
P

Peter Jamieson

Hi Bob,

I am also feeling my way in this area, so this is just a guess on my
part, but...

When you made your reference to Word 2002, did you go to Project->Add
Reference, then select the COM tab and look for Microsoft Word 10.0
Object Library? (or something along those lines?)

If so, I'm guessing that you need to get the Office 2002 Interop
assemblies and make the reference to that instead via the list in the
..NET tab

Trouble is I'm not sure precisely what you need in this area - there's
an old KB article at

http://support.microsoft.com/kb/328912

which has some info. about this but I do not know how relevant that is
to the VB2008 / Office2002 combination, or, for that matter, the
WordBasic problem - the code here works with Word 2007 whether I
reference the Interop Assembly or the relevant .com, and I can't test
with Office 2002 right now. However, I'll see if I can find out anything
else.

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks Peter. I appreciate your help. You'll have to be patient as I'm a
novice. I'm using the vb.net express 2008 platform. The OS is Vista. I have a
MS Office 10.0 library reference and I'm using Word 2002. I've added the
namespace in module1: Imports Microsoft.Office.Interop. The namespace is also
checked on the project page. I copied and pasted your code into the sub main.
I changed to my document and then started the debugger. The document opened
fine but I then received this unhandled exception:

Public member 'showtablegridlines' on type '_ComObject' not found.

Now i'm reallly confused.

Thanks,
Bob


Peter said:
Well, my very simple test routine just does

Imports Microsoft.Office.Interop

Module Module1
Private oWord As Word.Application
Private oDoc As Word.Document
Private oWB As Object
Sub main()
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Open("c:\a\noborders.docx")
oWB = oWord.WordBasic
oWB.showtablegridlines()
End Sub

End Module

Does that give you any clues?

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks for your help Peter. I placed the 'Private oWB As Object' in the Class
area and the
[quoted text clipped - 37 lines]
Thanks
Bob
 
T

tiki99 via OfficeKB.com

Thanks again Peter.

I looked at the .NET tab references and could not find anything for Word or
Office. I read somewhere that VBA encompasses the WordBasic command set and
that certain commands(as show/hide gridlines) could only be accessed through
VBA/WordBasic. I guess the problem is how to access and utilize those
WordBasic commands. I know I have to have the interop.word.dll in the same
folder as the .exe and so is interop.office.dll and interop.microsoft.office.
core.dll. I checked and saw that I have both the Word 10.0 library and the
Office 10.0 library referenced. And as I said, the VBA commands are fine as
it creates tables and uses bookmarks etc.

If you come up with any suggestions, pleas let me know.

Thanks,
Bob

Peter said:
Hi Bob,

I am also feeling my way in this area, so this is just a guess on my
part, but...

When you made your reference to Word 2002, did you go to Project->Add
Reference, then select the COM tab and look for Microsoft Word 10.0
Object Library? (or something along those lines?)

If so, I'm guessing that you need to get the Office 2002 Interop
assemblies and make the reference to that instead via the list in the
.NET tab

Trouble is I'm not sure precisely what you need in this area - there's
an old KB article at

http://support.microsoft.com/kb/328912

which has some info. about this but I do not know how relevant that is
to the VB2008 / Office2002 combination, or, for that matter, the
WordBasic problem - the code here works with Word 2007 whether I
reference the Interop Assembly or the relevant .com, and I can't test
with Office 2002 right now. However, I'll see if I can find out anything
else.

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks Peter. I appreciate your help. You'll have to be patient as I'm a
novice. I'm using the vb.net express 2008 platform. The OS is Vista. I have a
[quoted text clipped - 40 lines]
 
D

Doug Robbins - Word MVP

Have you tried

oWord.WordBasic.ShowTableGridlines

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

tiki99 via OfficeKB.com said:
Thanks again Peter.

I looked at the .NET tab references and could not find anything for Word
or
Office. I read somewhere that VBA encompasses the WordBasic command set
and
that certain commands(as show/hide gridlines) could only be accessed
through
VBA/WordBasic. I guess the problem is how to access and utilize those
WordBasic commands. I know I have to have the interop.word.dll in the same
folder as the .exe and so is interop.office.dll and
interop.microsoft.office.
core.dll. I checked and saw that I have both the Word 10.0 library and the
Office 10.0 library referenced. And as I said, the VBA commands are fine
as
it creates tables and uses bookmarks etc.

If you come up with any suggestions, pleas let me know.

Thanks,
Bob

Peter said:
Hi Bob,

I am also feeling my way in this area, so this is just a guess on my
part, but...

When you made your reference to Word 2002, did you go to Project->Add
Reference, then select the COM tab and look for Microsoft Word 10.0
Object Library? (or something along those lines?)

If so, I'm guessing that you need to get the Office 2002 Interop
assemblies and make the reference to that instead via the list in the
.NET tab

Trouble is I'm not sure precisely what you need in this area - there's
an old KB article at

http://support.microsoft.com/kb/328912

which has some info. about this but I do not know how relevant that is
to the VB2008 / Office2002 combination, or, for that matter, the
WordBasic problem - the code here works with Word 2007 whether I
reference the Interop Assembly or the relevant .com, and I can't test
with Office 2002 right now. However, I'll see if I can find out anything
else.

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks Peter. I appreciate your help. You'll have to be patient as I'm a
novice. I'm using the vb.net express 2008 platform. The OS is Vista. I
have a
[quoted text clipped - 40 lines]
Thanks
Bob
 
T

Tony Jollans

There seems to be some confusion here. Where are you coding this?

The command WordBasic.ShowTableGridlines should work in *VBA*

As I understand it, if you are using VB.NET, you can't reference the
Wordbasic commands quite so easily. Does Peter's original suggestion work?
And, if not, what error do you get?

--
Enjoy,
Tony

www.WordArticles.com

tiki99 via OfficeKB.com said:
Thanks again Peter.

I looked at the .NET tab references and could not find anything for Word
or
Office. I read somewhere that VBA encompasses the WordBasic command set
and
that certain commands(as show/hide gridlines) could only be accessed
through
VBA/WordBasic. I guess the problem is how to access and utilize those
WordBasic commands. I know I have to have the interop.word.dll in the same
folder as the .exe and so is interop.office.dll and
interop.microsoft.office.
core.dll. I checked and saw that I have both the Word 10.0 library and the
Office 10.0 library referenced. And as I said, the VBA commands are fine
as
it creates tables and uses bookmarks etc.

If you come up with any suggestions, pleas let me know.

Thanks,
Bob

Peter said:
Hi Bob,

I am also feeling my way in this area, so this is just a guess on my
part, but...

When you made your reference to Word 2002, did you go to Project->Add
Reference, then select the COM tab and look for Microsoft Word 10.0
Object Library? (or something along those lines?)

If so, I'm guessing that you need to get the Office 2002 Interop
assemblies and make the reference to that instead via the list in the
.NET tab

Trouble is I'm not sure precisely what you need in this area - there's
an old KB article at

http://support.microsoft.com/kb/328912

which has some info. about this but I do not know how relevant that is
to the VB2008 / Office2002 combination, or, for that matter, the
WordBasic problem - the code here works with Word 2007 whether I
reference the Interop Assembly or the relevant .com, and I can't test
with Office 2002 right now. However, I'll see if I can find out anything
else.

Peter Jamieson

http://tips.pjmsn.me.uk
Thanks Peter. I appreciate your help. You'll have to be patient as I'm a
novice. I'm using the vb.net express 2008 platform. The OS is Vista. I
have a
[quoted text clipped - 40 lines]
Thanks
Bob
 
T

tiki99 via OfficeKB.com

I'm using VB.NET 2008, and all the other VBA functions are working fine. I
have a table that I wish to have the gridlines turned off programmatically. I
tried Peter's suggestion but I received a:

Public member 'showtablegridlines' on type '_ComObject' not found.

error.

The oWord object shows WordBasic but not oWord.WordBasic.showtablegridlines().
If that makes any sense.

Thanks for your help,
Bob


Tony said:
There seems to be some confusion here. Where are you coding this?

The command WordBasic.ShowTableGridlines should work in *VBA*

As I understand it, if you are using VB.NET, you can't reference the
Wordbasic commands quite so easily. Does Peter's original suggestion work?
And, if not, what error do you get?
Thanks again Peter.
[quoted text clipped - 53 lines]
 
T

Tony Jollans

Well, I'm not a .net programmer so I don't quite know why that should give
that error.

However, you don't need to use WordBasic; the View object has a
TableGridlines property, so try something like

oWord.ActiveWindow.View.TableGridlines = False

--
Enjoy,
Tony

www.WordArticles.com

tiki99 via OfficeKB.com said:
I'm using VB.NET 2008, and all the other VBA functions are working fine. I
have a table that I wish to have the gridlines turned off
programmatically. I
tried Peter's suggestion but I received a:

Public member 'showtablegridlines' on type '_ComObject' not found.

error.

The oWord object shows WordBasic but not
oWord.WordBasic.showtablegridlines().
If that makes any sense.

Thanks for your help,
Bob


Tony said:
There seems to be some confusion here. Where are you coding this?

The command WordBasic.ShowTableGridlines should work in *VBA*

As I understand it, if you are using VB.NET, you can't reference the
Wordbasic commands quite so easily. Does Peter's original suggestion work?
And, if not, what error do you get?
Thanks again Peter.
[quoted text clipped - 53 lines]
Thanks
Bob
 
T

tiki99 via OfficeKB.com

Thanks everyone for your help. Tony...sometimes solutions are so obvious I
overlook them.

Thanks again,
Bob

Tony said:
Well, I'm not a .net programmer so I don't quite know why that should give
that error.

However, you don't need to use WordBasic; the View object has a
TableGridlines property, so try something like

oWord.ActiveWindow.View.TableGridlines = False
I'm using VB.NET 2008, and all the other VBA functions are working fine. I
have a table that I wish to have the gridlines turned off
[quoted text clipped - 25 lines]
 
D

Doug Robbins - Word MVP via msnews

I guess I gave you a bum steer there. But as I did not find the
ActiveWindow.View.TableGridlines, I resorted to using the macro recorder to
come up with the WordBasic command.

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

tiki99 via OfficeKB.com said:
Thanks everyone for your help. Tony...sometimes solutions are so obvious I
overlook them.

Thanks again,
Bob

Tony said:
Well, I'm not a .net programmer so I don't quite know why that should give
that error.

However, you don't need to use WordBasic; the View object has a
TableGridlines property, so try something like

oWord.ActiveWindow.View.TableGridlines = False
I'm using VB.NET 2008, and all the other VBA functions are working fine.
I
have a table that I wish to have the gridlines turned off
[quoted text clipped - 25 lines]
Thanks
Bob
 
P

Peter Jamieson

Thanks for cutting through that particular knot.

FWIW, I decided to try to replicate the OP's environment for my own
reasons - unnecessarily as it turned out because the main reason why he
couldn't use Wordbasic.ShowTableGridLines is because
WordBasic.ShowTableGridLines only arrived in Word 2007. It's not there
in Word 2002 (the OP's version) or Word 2003, which both have a
TableGridLines that does much the same thing.

ISTR a discussion some time ago about why Microsoft is still adding
things to WordBasic, in some cases apparently without a VBA equivalent -
if anyone has the definitive answer I'd be interested to hear it.

Peter Jamieson

http://tips.pjmsn.me.uk
 
T

Tony Jollans

Hi Peter,

I have no definitive knowledge, but ...

I don't think anything is actually being added to WordBasic; it's just that
all (English) Word commands (see Alt+F8, Word Commands) can be executed
directly through WB, so any new Word commands automatically appear there.

The Word Object Model, which controls what can, or can't, be done in VBA is
not tied to Word commands and, I presume, has to be separately and
independently updated for each new release.
 

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