Automatically generating a word table

PhilThomas

New Member
Joined
Jul 5, 2004
Messages
21
Hi

I have to do some network patch panel layouts for engineers to fill in for us in word. Each site is different and has different kit. I would like to write a macro that would ask me for each document the following information.

1) How many rooms? Example answer 5

From this it would know to ask me for 5 sets of kit. 1 for each room.

2) How many ports in the room are utp and how many are fibre. This should calculate what kit is going into each room as we have set kit for certain numbers of ports.

Ideally this should then autogenerate a table for me for each room ala

[Title Bar] Room: Roomcode
[Row 1] Current patch | New Patch | Port
[Row 2] G1 | G1 | FastEthernet0/1/1
[Row 3] G2 | G4 | FatThernet0/1/2

where G1, G2 G4 would be filled in by the engineer, I have simply included them for clarity. The auto generated table would not include them.

Any ideas greatly appreciated. I thought of writign it in php but don't know how to autocreate a table in word with the correct syntax. I can't make it a html document as there is other stuff int here and they want it as word.

Thanks
Phil
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Sorry, just to update

I can create a table statically from a macro using

Sub Macro2()
'
' Macro2 Macro
'
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=48, NumColumns _
:=3
Selection.TypeText Text:="Port"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="New Port"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Switchport"
Selection.MoveDown Unit:=wdLine, Count:=1
Do While Counter < 20 ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
Selection.TypeText Text:="FastEthernet1/0/" & Counter
Selection.MoveDown Unit:=wdLine, Count:=1
Loop
End Sub

Its how I get the value of Counter in there and into other variables that is the problem.

Thanks
Phil
 
Upvote 0
Phil

If you want user input the basic way is to use an input box.

eg

Code:
Do
    Counter = InputBox("Please enter no of rooms", "No of rooms", 20)
    
    If Not IsNumeric(Counter) Then
        MsgCancel = MsgBox("You haven't entered a number. Do you wish to continue?", vbYesNo + vbInformation)
        If MsgCancel = vbNo Then Exit Sub
    End If
    
Loop Until IsNumeric(Counter)
 
Upvote 0
Norie

Thank you very much for this. Never had to do user input before.
:pray:

Is there anyway of offering the user a dropdown box as a user input box?

Do you know of a good vba documentation website as well :oops:

Thanks
Phil
 
Upvote 0
Phil

It's been a while since I worked with VBA in Word but I'm pretty sure you could create a UserForm with dropdowns etc
 
Upvote 0
Norie

From the documentation I have found on the web it suggests that a userform is not editable. Therefore I cannot generate the table afterwards as the document is not editable :(

Phil
 
Upvote 0
Phil

I think you might be getting mixed up with a form.

Open the VBA editor (ALT+F11). On the Insert menu choose UserForm.

You should now have a blank form which you can add textboxes, dropdowns, command buttons etc.
 
Upvote 0

Forum statistics

Threads
1,216,124
Messages
6,128,997
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top