Author Topic: Referencing WSH Object Types from within VBA  (Read 2542 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Referencing WSH Object Types from within VBA
« on: November 01, 2007, 03:51:21 PM »

Hi

I do some VBScript as well as VBA. In VBA, I noticed I can set a type reference to The MS Scripting Runtime Type Library and that gives me The FSO Objects and methods but does anyone know if I can get a reference to The WSH Objects in VBA as well?

Thank you

Mark

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Referencing WSH Object Types from within VBA
« Reply #1 on: November 01, 2007, 03:52:41 PM »
I just sent you an email, but Yes, set a reference to the Wsh in Tools References
« Last Edit: November 01, 2007, 03:55:26 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

ML

  • Guest
Re: Referencing WSH Object Types from within VBA
« Reply #2 on: November 01, 2007, 03:54:42 PM »

EXCELLENT!!!!!!!!

Thank you sir!

Now, nothing can stop us!!!!!  hahahaha   :)


CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Referencing WSH Object Types from within VBA
« Reply #3 on: November 01, 2007, 04:36:40 PM »
Along the same lines, how would one set the default paper size via VBScript?  I have this code to set default printer, but I cannot find a way to tell it to use 11x17 paper

Code: [Select]
Option Explicit
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter "\\Printers1\SDP003"
WScript.Quit
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

ML

  • Guest
Re: Referencing WSH Object Types from within VBA
« Reply #4 on: November 01, 2007, 04:47:06 PM »

Hey CM

If I get time, I will look into it for you later
I wonder if a metod even exists for doing so?

Mark

MP

  • Seagull
  • Posts: 17529
Re: Referencing WSH Object Types from within VBA
« Reply #5 on: November 01, 2007, 05:28:24 PM »
Along the same lines, how would one set the default paper size via VBScript? 

Good question. I'd start here.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ML

  • Guest
Re: Referencing WSH Object Types from within VBA
« Reply #6 on: November 01, 2007, 05:30:06 PM »

Excellent Site!

Thanks MP, I will certainly use it

Mark

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Referencing WSH Object Types from within VBA
« Reply #7 on: November 01, 2007, 05:42:07 PM »
And to think I spent all this time on MSDN, I totally forgot about TechNet
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

MP

  • Seagull
  • Posts: 17529
Re: Referencing WSH Object Types from within VBA
« Reply #8 on: November 01, 2007, 05:55:53 PM »
Your welcome guys. I use it a fair amount in concert with one of my books "Advanced VBScript", Jones, Hicks ... most of which is do-able in / translatable to LISP ...

Code: [Select]
(defun _GetPrinterClientInfo ( / olePrn result )

    (vl-catch-all-apply
       '(lambda ( )
            (setq
                olePrn (vlax-create-object "OlePrn.PrinterURL")
                result (vlax-get-property olePrn 'ClientInfo)
            )
        )
    )

    (vl-catch-all-apply
       '(lambda ( )
            (vlax-release-object olePrn)
        )
    )

    (if result result 0)

)

(defun _DecodePrinterUnicodeName ( prnName / oleCvr result )

    (vl-catch-all-apply
       '(lambda ( )
            (setq
                oleCvt (vlax-create-object "OlePrn.OleCvt")
                result (vlax-get-property oleCvt 'DecodeUnicodeName prnName)
            )
        )
    )

    (vl-catch-all-apply
       '(lambda ( )
            (vlax-release-object oleCvt)
        )
    )

    (if result result "")

)

(defun _ConnectToPrinter ( server printerUnicodeName / oleInstall share platform result )

    (vl-catch-all-apply
       '(lambda ( )
            (setq
                oleInstall (vlax-create-object "OlePrn.OleInstall.1")
                share      (_DecodePrinterUnicodeName printerUnicodeName)
                platform   (itoa (_GetPrinterClientInfo))
            )
            (vlax-invoke-method
                oleInstall
               'InstallPrinter
                (strcat "\\\\" server "\\" share)
                (strcat
                    "http://"
                    server
                    "/printers/"
                    printerUnicodeName
                    "/.printer?createexe&"
                    platform
                )
            )
            (setq result t)
        )
    )

    (vl-catch-all-apply
       '(lambda ( )
            (vlax-release-object oleInstall)
        )
    )

    result

)   

...

Have fun.

:P

\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

ML

  • Guest
Re: Referencing WSH Object Types from within VBA
« Reply #9 on: November 02, 2007, 09:36:36 AM »
Oh, that's pretty cool MP
So, you use VBScript along with LISP?

I am not very good with LISP however my boss in really good at it.
He's been at it for 15 or 20 years. He is also good with VBA but excellent at LISP.

I am a VBA guy and that is simply because I discovered VBA first and also latched on early to the fact that I can connect with other VB Enabled programs such as Excel with it. Then, I found out about VBScript and realized that I could do a lot of system type things and write something simply in an ascii file, double click it and launch it; that is outstanding for ease of use and to to share with other computer users.

Then, I realized that I could use VBScript with VBA together which blew my mind even further. LOL
It is interesting how we discover new things and learn to blend them together.

Having said that, I think I use to under value LISP or may be even look down on it as old, outdated, only specific only to ACAD; then when I started working here, I saw how my boss has and is uses it a lot. You can do SO many things with LISP on the fly in ACAD.
Selection Sets, creating variables etc.

So, I don't think that I will really ever dive too far into LISP but I would certainly like to get a little more versed in it, at least for the on the fly tools. That would be cool if we had a post or section for using LISP on the fly :)

Mark
The whole VB user guide is on there for free as you know.

Honestly, I am not trying to understand all of the ins and outs of VBScript.
Do I really care to know that W