I would be interested in hearing from Philip Spaelti and others how Visual Basic in MS Word compares to the Nisus macro language.
Nisus macro language versus Visual Basic
Re: Nisus macro language versus Visual Basic
Perl has a famous motto: "[Perl] makes easy things easy, and hard things possible." (One might argue with this statement about Perl
)
But my quip about Visual Basic is: "VB makes easy things hard, and hard things impossible!"
Part of my assessment of VB might be lack of knowledge, but whenever I have decided I would give it a go, and learn enough, so I could complete a project in Word or Excel (rather than just import it into Nisus and do it there), I have always come away frustrated. Just as one good example, VB does not have a sort command! You cannot read in a bunch of data, sort it, and put it back out. Not possible.
Maybe it's possible to put the data into an Excel sheet, sort there, then remove the Excel sheet, who knows… I just can be bothered to spend that much time mucking through those complicated "libraries" that make up the command system of VB.
And Word (and VB) does not have any true implementation of grep (= Nisus Powerfind). Certainly nothing like Nisus has. Nisus Powerfind is probably about 90% of what you need to complete most useful tasks.
Why is it called Visual Basic? VB is neither visual nor basic.
And finally, a lot of people complain about the Nisus Macro Language Reference. But at least it has all the commands spelled out, and with some bare-bones examples and explanations.
But for VB there is no (free) documentation that I have ever been able to find. I could be wrong, but I think this might be to not undermine the business of providers who want to sell you this stuff.

But my quip about Visual Basic is: "VB makes easy things hard, and hard things impossible!"
Part of my assessment of VB might be lack of knowledge, but whenever I have decided I would give it a go, and learn enough, so I could complete a project in Word or Excel (rather than just import it into Nisus and do it there), I have always come away frustrated. Just as one good example, VB does not have a sort command! You cannot read in a bunch of data, sort it, and put it back out. Not possible.
Maybe it's possible to put the data into an Excel sheet, sort there, then remove the Excel sheet, who knows… I just can be bothered to spend that much time mucking through those complicated "libraries" that make up the command system of VB.
And Word (and VB) does not have any true implementation of grep (= Nisus Powerfind). Certainly nothing like Nisus has. Nisus Powerfind is probably about 90% of what you need to complete most useful tasks.
Why is it called Visual Basic? VB is neither visual nor basic.
And finally, a lot of people complain about the Nisus Macro Language Reference. But at least it has all the commands spelled out, and with some bare-bones examples and explanations.
But for VB there is no (free) documentation that I have ever been able to find. I could be wrong, but I think this might be to not undermine the business of providers who want to sell you this stuff.
philip
Re: Nisus macro language versus Visual Basic
I found this on the Web. I don't know if it is of any help.VB does not have a sort command! You cannot read in a bunch of data, sort it, and put it back out. Not possible.
If the data is a Word table, use
Code: Select all
Sub SortTableByFirstColumn()
If Selection.Information(wdWithInTable) Then
Selection.Tables(1).Sort ExcludeHeader:=False, _
FieldNumber:=1, _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending
Else
MsgBox "Please place the cursor inside a table to sort."
End If
End Sub
Code: Select all
Sub ImportAndSortCSV()
Dim fd As FileDialog
Dim filePath As String
Dim fileNum As Integer
Dim fileLine As String
Dim rowData() As String
Dim docTable As Table
Dim row As Integer, col As Integer
' Ask user to pick CSV file
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Title = "Select a CSV File"
fd.Filters.Clear
fd.Filters.Add "CSV Files", "*.csv"
If fd.Show <> -1 Then
MsgBox "No file selected."
Exit Sub
End If
filePath = fd.SelectedItems(1)
' Read file and insert table
fileNum = FreeFile
Open filePath For Input As #fileNum
row = 0
Do Until EOF(fileNum)
Line Input #fileNum, fileLine
rowData = Split(fileLine, ",")
If row = 0 Then
' First row: create table
Set docTable = ActiveDocument.Tables.Add(Selection.Range, 1, UBound(rowData) + 1)
Else
docTable.Rows.Add
End If
For col = 0 To UBound(rowData)
docTable.Cell(row + 1, col + 1).Range.Text = Trim(rowData(col))
Next col
row = row + 1
Loop
Close #fileNum
' Sort by first column
docTable.Sort ExcludeHeader:=False, _
FieldNumber:=1, _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending
End Sub
One can also write macros in LibreOffice. Have you any experience with LibreOffice macros?
Re: Nisus macro language versus Visual Basic
Hi Þorvarður,
Thanks for going to the trouble of digging this up, I guess…
That first macro that you are posting is a good example of the sh#!-show that is VB. All it's doing is trying to sort a table by the first column, using the built-in ability of Word to sort a table by the first column. I mean you don't need a macro to do this, you can just do it by the menu command. The only reason for writing such a macro is because you wanted to write a more complicated editing macro that needed such a step in the middle. In Nisus you would just write:
(Okay, the VB does some checking and selecting too, but in Nisus that wouldn't require a lot of code either.)
The latter macro seems to create an interactive macro that will open a CSV file and then put the data into a table and then sort it. Again this is just taking 3 steps that I can do by hand and combining that into a macro. And for that you need 46 lines of incomprehensible code!
In the case I was referring to, I wanted to use VB to overcome a limitation in Word (or maybe it was Excel). For that it seems I would have had to write my own sort algorithm. Something, i might add, I have done more than once in Nisus Macro Language, and is quite doable, but in VB would probably be a nightmare.
Like I said: VB makes easy things hard, and hard things impossible.
Thanks for going to the trouble of digging this up, I guess…
That first macro that you are posting is a good example of the sh#!-show that is VB. All it's doing is trying to sort a table by the first column, using the built-in ability of Word to sort a table by the first column. I mean you don't need a macro to do this, you can just do it by the menu command. The only reason for writing such a macro is because you wanted to write a more complicated editing macro that needed such a step in the middle. In Nisus you would just write:
Code: Select all
Table:Sort Rows:Sort by Selected Column Ascending (A-Z)
The latter macro seems to create an interactive macro that will open a CSV file and then put the data into a table and then sort it. Again this is just taking 3 steps that I can do by hand and combining that into a macro. And for that you need 46 lines of incomprehensible code!
In the case I was referring to, I wanted to use VB to overcome a limitation in Word (or maybe it was Excel). For that it seems I would have had to write my own sort algorithm. Something, i might add, I have done more than once in Nisus Macro Language, and is quite doable, but in VB would probably be a nightmare.
Like I said: VB makes easy things hard, and hard things impossible.
philip
Re: Nisus macro language versus Visual Basic
It's been a while that I have opened LibreOffice, and I wasn't aware that they had a macro language. But maybe this is something added more recently. I could imagine that LibreOffice macros are reasonably doable to write (and actually useful


philip
Re: Nisus macro language versus Visual Basic
Anyhow, maybe I should try to clarify the difference between a language like VB and Nisus Macro language.
In Nisus as you are probably aware, there is a long standing separation of two "dialects" for macro writing. The first is really just putting the menu commands in a file, with some additions to take care of user interaction, when necessary. This will allow a user to combine a multi-step task into a single command.
The second is the Macro Language per se. This gives a whole other approach with added features and data structures, which allow you to manipulate the data of your file and then output the results. This gives you the ability to effectively create new abilities for Nisus.
VB is really mainly just the first thing, but instead of writing the commands in an easy to understand way, you have to use the internal object system, and to do things you have to hunt through the incomprehensible object property libraries (which as I said are not obviously documented or explained). And the programming style is reminiscent of languages like FORTRAN or some throwback to the 1950s where you have to have "think like a machine" (consider all those "dim" statements in the code above. Why?). I also can't see any real data structures like hashes, or the like, that can easily be used. It’s possible they exist, but I haven't had the patience to find out.
In Nisus as you are probably aware, there is a long standing separation of two "dialects" for macro writing. The first is really just putting the menu commands in a file, with some additions to take care of user interaction, when necessary. This will allow a user to combine a multi-step task into a single command.
The second is the Macro Language per se. This gives a whole other approach with added features and data structures, which allow you to manipulate the data of your file and then output the results. This gives you the ability to effectively create new abilities for Nisus.
VB is really mainly just the first thing, but instead of writing the commands in an easy to understand way, you have to use the internal object system, and to do things you have to hunt through the incomprehensible object property libraries (which as I said are not obviously documented or explained). And the programming style is reminiscent of languages like FORTRAN or some throwback to the 1950s where you have to have "think like a machine" (consider all those "dim" statements in the code above. Why?). I also can't see any real data structures like hashes, or the like, that can easily be used. It’s possible they exist, but I haven't had the patience to find out.
philip