Let's go through that code for minute:
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
End Sub
So bascially Dim is like saying to VBA to declare a variable. For this code above, the name of the variable is SwApp short for SolidWorksApplication. Be aware that variable names cannot start with a numeric or have spaces in them.
Declaring variables is something that gets old with time when you're programming a SolidWorks macro, however, it is a necessary evil, otherwise the VBA will not know what application we're using.
And then, there is this "As" thing which I presume you'll guess it for the type of the variable.
By default SolidWorks will declare the SwApp as an Object but in our case we're going to change that to SldWorks.SldWorks which is the SolidWorks object for the entire SolidWorks Application according the SolidWorks API documentation.
By doing that, we've declared the Solidworks application variable. That means, we can now access and use the SolidWorks application. We can't do much with just the Solidworks application but it gets the job done for the Hello World tutorial.
The next line is sub main()
Basically, the sub stands for subroutine which is a procedure if you will. Think of a procedure as a block of instructions with a name. Subroutines and functions serve for the purpose of modular programming. They make your code reusable. So, I think we can be clear that we've declared a subroutine called "main".
Now, the next line is: Set SwApp = Application.SldWorks
Set is used whenever you want to reference a variable. With Set, we're telling the VBA that our variable SwApp is referenced to the SolidWorks Application using "Application.SldWorks".
With that done, we can get to do the Hello World.
We're going now to add the follow line to the code:
Swapp.SendMsgToUser("Hello World, this is my first macro")
What we did was that we basically told SolidWorks to use the method SendMsgToUser2 to send the message to the user with the string "HelloWorld, this is my first macro".
The last line is end which tells the VBA that our main procedure has ended.
Now to wrap everything up, your code should look like the following:
Dim SwApp as SldWorks.SldWorks
Sub main()
Set SwApp = Application.SldWorks
SwApp.SendMsgToUser("Hello World, this is my first macro")
End