Word syntax

Hello everybody,
Sometimes I meet this syntax “With...End With” in other languages and there I can not adapt it to my code in RB.
Is there an equivalent in RB of that command “With...End With”?
That function allows to add columns in a Word document.

With Selection.PageSetup.TextColumns
  .SetCount NumColumns:=3
  .EvenlySpaced = True
  .LineBetween = False
  .Width = CentimetersToPoints(16)
  End With

If anyone could help me, that would be great.

Xojo does not have WITH… END WITH and no equivalent

you sample needs to become

 Selection.PageSetup.TextColumns.SetCount NumColumns=3
 Selection.PageSetup.TextColumns.EvenlySpaced = True
 Selection.PageSetup.TextColumns.LineBetween = False
 Selection.PageSetup.TextColumns.Width = CentimetersToPoints(16)

the lack of this command structure had been a subject of many forum topics over the last few years

Thank you Dave,
Yes I tried that but already at the first line I block.
I used different syntaxes but nothing to do:


you have a “:” in that line… remove it

if still issues… print the error message

Strongly recommend this:


[quote]Word.Selection.PageSetup.TextColumns.SetCount.NumColumns=3[/quote] Error message : OLEException

[quote]Word.Selection.PageSetup.TextColumns.SetCount NumColumns=3[/quote] Error message before compilation : That method doesn’t exist

You forgot a dot between SetCount and NumColumns…

Those errors are not related to the “syntax” of WITH… but to what the command is actually trying to do

I know it is not related to WITH… but as you can see here above I have tried with dot and without.

my point was, the syntax is right… the code is wrong… you need to investigate those errors as your issue is no long related to WITH
something else you converted (or failed to convert) is now the issue

Does this help?

[code] dim sel as WordSelection
sel = doc.Select //something

dim selps as WordPageSetup
selps = sel.PageSetup

dim textcolwidth as WordTextColumns
textcolwidth = selps.TextColumns //this is the equivalent of textcolumns .with
textcolwidth.SetCount = 3
textcolwidth.EvenlySpaced = true
textcolwidth.LineBetween = false
textcolwidth = word.CentimetersToPoints(16)[/code]

[quote=434971:@Jeff Tullin]Strongly recommend this:

https://forum.xojo.com/25571-i-wish-i-knew-how-to-program-word-with-xojo-in-windows [/quote]

A BIG +! to Jeff’s statement.

Its less than $20 USD and is written in a way that even dummies like me could get code up and going quick. You’ll realize the return on your investment in the first 30 minutes of usage!

Thank you all,
Until now I recorded a macro to know the code of each function so I do not really need a book but here at every line I have a problem and I still have 2.
Jeff thank you for your code. Indeed as you have presented it, we have the equivalent of “With … End with”.
Here is my last condensed code :

Word.Selection.PageSetup.TextColumns.SetCount(3) OK but doesn’t work with =

Word.Selection.PageSetup.TextColumns.EvenlySpaced = True // OLEexception error but working with False

Word.Selection.PageSetup.TextColumns.LineBetween = False // OK

Word.Selection.PageSetup.TextColumns.Width = Word.PointsToInches(16) OK but OLEexception error with CentimetersToPoints

Thanks for your help