VB Script Check

Author Message
SteveElmore

  • Total Posts : 10
  • Scores: 0
  • Reward points : 0
  • Joined: 1/17/2012
  • Status: offline
VB Script Check Tuesday, January 17, 2012 10:07 AM (permalink)
0
I downloaded a script in an effort to force a default Outlook signature for our entire company that would pull information from AD. It appears to work halfway where it will insert my name and company logo and address, but the rest of the info displays the variable identifier and not the actual AD info. Is there someone who can point out any obvious errors to me because I have ZERO scripting experience.
 
Thanks.
 
On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")

Set WshShell = CreateObject("WScript.Shell")

strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)

strName = objUser.FullName
strTitle = objUser.Description
strCred = objUser.info
strStreet = objUser.StreetAddress
strLocation = objUser.l
strPostCode = objUser.PostalCode
strPhone = objUser.TelephoneNumber
strMobile = objUser.Mobile
strFax = objUser.FacsimileTelephoneNumber
strEmail = objUser.mail

Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature

Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

objSelection.Font.Name = "Arial"
objSelection.Font.Size = 14
objSelection.Font.Bold = true
objSelection.Font.Color = RGB(0,34,102)
if (strCred) Then objSelection.TypeText strName & ", " & strCred Else objSelection.TypeText strName
objSelection.TypeText Chr(11)
objSelection.Font.Size = 11
objSelection.Font.Bold = false
objSelection.Font.Color = RGB(0,0,0)
objSelection.TypeText strTitle
objSelection.TypeText Chr(11)
objselection.TypeText Chr(11)
objSelection.InlineShapes.AddPicture("\\xxxxx.com\SYSVOL\xxxxx.COM\scripts\tg_logo.jpg")
objSelection.TypeParagraph()
objSelection.Font.Size = 12
objSelection.Font.Bold = true
objSelection.Font.Color = RGB(75,75,75)
objSelection.TypeText "North America - Europe - Asia"
objSelection.TypeText Chr(11)
objSelection.Font.Size = 11
objSelection.Font.Color = RGB(0,0,0)
objSelection.Font.Bold = false
objSelection.TypeText strStreet
objSelection.TypeText Chr(11)
objSelection.TypeText strLocation
objSelection.TypeText Chr(11)
objSelection.TypeText PostCode
objSelection.TypeText Chr(11)
objSelection.TypeText "Phone: " & strPhone
objSelection.TypeText Chr(11)
if (strFax) Then objSelection.TypeText "FAX: " & strFax & Chr(11)
if (strMobile) Then objSelection.TypeText "Mobile: " & strMobile & Chr(11)
objSelection.Font.Italic = true
objSelection.TypeText "email: " & strEmail
objSelection.Font.Italic = false
objSelection.TypeText Chr(11)
objSelection.TypeText "________________________________"
objSelection.TypeText Chr(11)
objSelection.TypeText "CONFIDENTIALITY NOTICE"

Set objSelection = objDoc.Range()

objSignatureEntries.Add "Full Signature", objSelection
objSignatureObject.NewMessageSignature = "Full Signature"

objDoc.Saved = True
objWord.Quit

Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature

Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

objSelection.Font.Name = "Arial"
objSelection.Font.Size = 10
if (strCred) Then objSelection.TypeText strName & ", " & strCred Else objSelection.TypeText strName
objSelection.TypeParagraph()
objSelection.TypeText strTitle
objSelection.TypeText Chr(11)

Set objSelection = objDoc.Range()

objSignatureEntries.Add "Reply Signature", objSelection

objSignatureObject.ReplyMessageSignature = "Reply Signature"

objDoc.Saved = True
objWord.Quit
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:VB Script Check Wednesday, January 18, 2012 3:12 AM (permalink)
    0
    The first step is to remove the global On Error Resume Next at the top of your script. Then see if you get errors.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      SteveElmore

      • Total Posts : 10
      • Scores: 0
      • Reward points : 0
      • Joined: 1/17/2012
      • Status: offline
      Re:VB Script Check Wednesday, January 18, 2012 4:54 AM (permalink)
      0
      Thanks. Here is the error message:
      Line 55
      Char 1
      Error: Type mismatch 'objSelection.TypeText'
      Code: 800A000D
       
      THe line of code in question is:
      objSelection.TypeText PostCode
      which I assume is the code to pull in the Zip Code from the AD account. I do not know the correct parameter to identify this AD field in the VBS script.
       
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:VB Script Check Wednesday, January 18, 2012 5:02 AM (permalink)
        0
        Actually it is the code to output the code to your word object. Since you get that information via this line:
         
        strPostCode = objUser.PostalCode
         
        And you try to use that information via this line:
         
        objSelection.TypeText PostCode
         
        Do you see an issue?
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          SteveElmore

          • Total Posts : 10
          • Scores: 0
          • Reward points : 0
          • Joined: 1/17/2012
          • Status: offline
          Re:VB Script Check Wednesday, January 18, 2012 5:12 AM (permalink)
          0
          I'm going to say that the "PostCode" identifier in line 55 should match the "PostalCode" identifier in that line you mentioned.
          So should they both be "PostCode" or "PostalCode" I've tried both and neither one seems to work.
          When I make them both say "PostalCode" I get the same error message.
          When I change them both to "PostCode" I get:
          Line 13
          Char 1
          Error: Object doesn't support this property or method: 'objUser.PostCode'
           
          So I assume this is an invalid identifier.
           
          #5
            ebgreen

            • Total Posts : 8227
            • Scores: 98
            • Reward points : 0
            • Joined: 7/12/2005
            • Status: offline
            Re:VB Script Check Wednesday, January 18, 2012 6:09 AM (permalink)
            0
            This line:
             
            strPostCode = objUser.PostalCode
             
            gets the value from AD and assigns it to a variable named strPostalCode
             
            in this line:
             
            objSelection.TypeText PostCode
             
            you are trying to write the contents of a variable named PostCode to the document. Do you have a variable named PostCode? No, you have a variable named strPostCode. Try writing that variable to the document.
            "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
            Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
            http://www.visualbasicscript.com/m_47117/tm.htm
             
            #6
              SteveElmore

              • Total Posts : 10
              • Scores: 0
              • Reward points : 0
              • Joined: 1/17/2012
              • Status: offline
              Re:VB Script Check Wednesday, January 18, 2012 6:49 AM (permalink)
              0
              I made those changes that and still got the same error. Here is part of the new script with what I believe are the correct variable identifiers:
               
              strPostCode = objUser.PostalCode
              strPhone = objUser.TelephoneNumber
              strMobile = objUser.Mobile
              strFax = objUser.FacsimileTelephoneNumber
              strEmail = objUser.mail
              Set objWord = CreateObject("Word.Application")
              Set objDoc = objWord.Documents.Add()
              Set objSelection = objWord.Selection
              Set objEmailOptions = objWord.EmailOptions
              Set objSignatureObject = objEmailOptions.EmailSignature
              Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
              objSelection.Font.Name = "Arial"
              objSelection.Font.Size = 14
              objSelection.Font.Bold = true
              objSelection.Font.Color = RGB(0,34,102)
              if (strCred) Then objSelection.TypeText strName & ", " & strCred Else objSelection.TypeText strName
              objSelection.TypeText Chr(11)
              objSelection.Font.Size = 11
              objSelection.Font.Bold = false
              objSelection.Font.Color = RGB(0,0,0)
              objSelection.TypeText strTitle
              objSelection.TypeText Chr(11)
              objselection.TypeText Chr(11)
              objSelection.InlineShapes.AddPicture("\\tweddle.com\SYSVOL\TWEDDLE.COM\scripts\tg_logo.jpg")
              objSelection.TypeParagraph()
              objSelection.Font.Size = 12
              objSelection.Font.Bold = true
              objSelection.Font.Color = RGB(75,75,75)
              objSelection.TypeText "North America - Europe - Asia"
              objSelection.TypeText Chr(11)
              objSelection.Font.Size = 11
              objSelection.Font.Color = RGB(0,0,0)
              objSelection.Font.Bold = false
              objSelection.TypeText strStreet
              objSelection.TypeText Chr(11)
              objSelection.TypeText strLocation
              objSelection.TypeText Chr(11)
              objSelection.TypeText PostalCode
               
              Again, this generates the same error message so I am not sure what else is incorrect
               
              Thanks for your help.
               
              #7
                ebgreen

                • Total Posts : 8227
                • Scores: 98
                • Reward points : 0
                • Joined: 7/12/2005
                • Status: offline
                Re:VB Script Check Wednesday, January 18, 2012 6:56 AM (permalink)
                0
                Use the variable that you are putting the data in.
                 
                objSelection.TypeText strPostCode
                 
                instead of
                 
                objSelection.TypeText PostalCode

                "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                http://www.visualbasicscript.com/m_47117/tm.htm
                 
                #8
                  SteveElmore

                  • Total Posts : 10
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 1/17/2012
                  • Status: offline
                  Re:VB Script Check Wednesday, January 18, 2012 7:41 AM (permalink)
                  0
                  THanks. That fixed that one. Now these are problematic:
                  strMobile = objUser.Mobile
                  strFax = objUser.FaxNumber
                  if (strFax) Then objSelection.TypeText "FAX: " & strFax & Chr(11)
                  if (strMobile) Then objSelection.TypeText "Mobile: " & strMobile & Chr(11)
                   
                  The errors I get with these lines are similar:
                  Line 59
                  Type mismatch '(string: "xxx-xxx-xxx")'
                   
                  To a novice coder like me, these lines look correct according to your previous posts. It looks the correct variables are being called.
                   
                  #9
                    ebgreen

                    • Total Posts : 8227
                    • Scores: 98
                    • Reward points : 0
                    • Joined: 7/12/2005
                    • Status: offline
                    Re:VB Script Check Wednesday, January 18, 2012 7:50 AM (permalink)
                    0
                    the variables look like they have the right names to me too. So what I would do is to use the VarType function (it's documented) to determine the data subtype of whatever is in those variables. It also wouldn't hurt to use WScript.Echo to see the contents of the variables.
                    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                    http://www.visualbasicscript.com/m_47117/tm.htm
                     
                    #10
                      SteveElmore

                      • Total Posts : 10
                      • Scores: 0
                      • Reward points : 0
                      • Joined: 1/17/2012
                      • Status: offline
                      Re:VB Script Check Tuesday, January 24, 2012 3:04 AM (permalink)
                      0
                      I've done some investigating but as I said before I'm a novice with 0 coding experience so I have no clue how to do what you said :-) My apologies. I figured this would be an easy script to implement in our corporate environment but obviously I was naive.
                       
                      #11
                        SteveElmore

                        • Total Posts : 10
                        • Scores: 0
                        • Reward points : 0
                        • Joined: 1/17/2012
                        • Status: offline
                        Re:VB Script Check Tuesday, January 24, 2012 3:29 AM (permalink)
                        0
                        SO here's what I figured out. In the AD account, there are dashes in the phone number that the VBS script doesn't like. When I remove the dashes the  script works , but I would like to use the dashes in the Outlook signature for aesthetic purposes.
                         
                        #12
                          ebgreen

                          • Total Posts : 8227
                          • Scores: 98
                          • Reward points : 0
                          • Joined: 7/12/2005
                          • Status: offline
                          Re:VB Script Check Tuesday, January 24, 2012 5:36 AM (permalink)
                          0
                          Can you expand on "doesn't like"? Throws an error? Doesn't read the value at all?
                          "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                          Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                          http://www.visualbasicscript.com/m_47117/tm.htm
                           
                          #13
                            dm_4ever

                            • Total Posts : 3687
                            • Scores: 82
                            • Reward points : 0
                            • Joined: 6/29/2006
                            • Location: Orange County, California
                            • Status: offline
                            Re:VB Script Check Tuesday, January 24, 2012 6:01 AM (permalink)
                            0
                            Have you tried something like
                             
                            if strFax <> "" Then objSelection.TypeText "FAX: " & strFax & Chr(11)
                            if strMobile <> "" Then objSelection.TypeText "Mobile: " & strMobile & Chr(11)
                            dm_4ever

                            My philosophy: K.I.S.S - Keep It Simple Stupid
                            Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
                            Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
                             
                            #14
                              SteveElmore

                              • Total Posts : 10
                              • Scores: 0
                              • Reward points : 0
                              • Joined: 1/17/2012
                              • Status: offline
                              Re:VB Script Check Tuesday, January 24, 2012 6:44 AM (permalink)
                              0
                              Thanks, dm! That worked! The error I was getting was another Type Mismatch and then it would display the phone number pulled from the AD account (i.e. "555-123-4567") after the error.
                               
                              #15
                                dm_4ever

                                • Total Posts : 3687
                                • Scores: 82
                                • Reward points : 0
                                • Joined: 6/29/2006
                                • Location: Orange County, California
                                • Status: offline
                                Re:VB Script Check Tuesday, January 24, 2012 7:32 AM (permalink)
                                0
                                I don't recall what is returned by objUser.Mobile if no value is present so you might want to make sure to test an account without a Mobile or Fax number to make sure the code still works for those folks.
                                dm_4ever

                                My philosophy: K.I.S.S - Keep It Simple Stupid
                                Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
                                Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
                                 
                                #16
                                  SteveElmore

                                  • Total Posts : 10
                                  • Scores: 0
                                  • Reward points : 0
                                  • Joined: 1/17/2012
                                  • Status: offline
                                  Re:VB Script Check Tuesday, January 24, 2012 7:45 AM (permalink)
                                  0
                                  I did notice that this line only brings in the "City" from the AD account. It does not bring in the "State"
                                   
                                  strLocation = objUser.l
                                   
                                  objSelection.TypeText strLocation
                                   
                                  Is there a way to pull this data into the signature via individual lines of code or are they combined in one line like the example above?
                                   
                                  #17
                                    SteveElmore

                                    • Total Posts : 10
                                    • Scores: 0
                                    • Reward points : 0
                                    • Joined: 1/17/2012
                                    • Status: offline
                                    Re:VB Script Check Tuesday, January 24, 2012 8:29 AM (permalink)
                                    0
                                    It works regardless of whether or not and text is in either phone field. If the field is empty, no data is displayed in the signature.
                                     
                                     
                                     
                                    #18

                                      Online Bookmarks Sharing: Share/Bookmark

                                      Jump to:

                                      Current active users

                                      There are 0 members and 1 guests.

                                      Icon Legend and Permission

                                      • New Messages
                                      • No New Messages
                                      • Hot Topic w/ New Messages
                                      • Hot Topic w/o New Messages
                                      • Locked w/ New Messages
                                      • Locked w/o New Messages
                                      • Read Message
                                      • Post New Thread
                                      • Reply to message
                                      • Post New Poll
                                      • Submit Vote
                                      • Post reward post
                                      • Delete my own posts
                                      • Delete my own threads
                                      • Rate post

                                      2000-2012 ASPPlayground.NET Forum Version 3.9