Jump to content

Problem with AutoIt script with some VBS


Lempke
 Share

Recommended Posts

I have some problems with my script. When I use the $ObjWord.Visible = False, it doesn't work. The output I get are "translated to" numbers instead of names that were in the variables. How is possible that sometimes a variable gets translated to a number. I have the same problem in an other scripts once in a while.

Also the "Close without saving" doesn't work. I've made a workaround with a copy of the document, but it's not the way I want to do it.

This is my script

$Type = IniRead("C:\User Management\USER.ini", "USERDATA", "Type", "")
$UserID = IniRead("C:\User Management\USER.ini", "USERDATA", "UserID", "")
$DisplayName = IniRead("C:\User Management\USER.ini", "USERDATA", "DisplayName", "")
$FirstName = IniRead("C:\User Management\USER.ini", "USERDATA", "FirstName", "")
$LastName = IniRead("C:\User Management\USER.ini", "USERDATA", "LastName", "")
$Location = IniRead("C:\User Management\USER.ini", "USERDATA", "Location", "")
$LocCode = IniRead("C:\User Management\USER.ini", "USERDATA", "LocCode", "")
$Department = IniRead("C:\User Management\USER.ini", "USERDATA", "Department", "")
$Function = IniRead("C:\User Management\USER.ini", "USERDATA", "Function", "")
$XPPW = IniRead("C:\User Management\USER.ini", "USERDATA", "XPPW", "")
$SapID = IniRead("C:\User Management\USER.ini", "USERDATA", "SapID", "")
$CopySapID = IniRead("C:\User Management\USER.ini", "USERDATA", "CopySapID", "")
$SAPPW = IniRead("C:\User Management\USER.ini", "USERDATA", "SAPPW", "")
$TELNR = IniRead("C:\User Management\USER.ini", "USERDATA", "TELNR", "")

FileCopy("C:\Program Files\AutoIt3\Scripts\User Management\Kopie van Gebruikersnaam en wachtwoord.doc", _
"C:\Program Files\AutoIt3\Scripts\User Management\Gebruikersnaam en wachtwoord.doc", 1)

$sFilePath = "C:\Program Files\AutoIt3\Scripts\User Management\Gebruikersnaam en wachtwoord.doc"                    
$ObjWord = ObjCreate("Word.Application")                                                                            
$ObjWord.Documents.Open($sFilePath)                                                                                 
$ObjWord.Visible = True                                                                                     
;WinActivate("Gebruikersnaam en wachtwoord.doc - Microsoft Word")
;WinWaitActive("Gebruikersnaam en wachtwoord.doc - Microsoft Word")

$ObjWord.Activedocument.Bookmarks("Text1").Select
$ObjWord.Selection.Text = $Location
$ObjWord.Activedocument.Bookmarks("Text2").Select
$ObjWord.Selection.Text = $LastName 
$ObjWord.Activedocument.Bookmarks("Text3").Select
$ObjWord.Selection.Text = $FirstName
$ObjWord.Activedocument.Bookmarks("Text4").Select
$ObjWord.Selection.Text = $Department
$ObjWord.Activedocument.Bookmarks("Text5").Select
$ObjWord.Selection.Text = (@MDAY & "-" & @MON & "-" & @YEAR)                                                                                
Select
Case $Type = 1
            $ObjWord.Activedocument.Bookmarks("Text6").Select
            $ObjWord.Selection.Text = $UserID                                                                                           
            $ObjWord.Activedocument.Bookmarks("Text7").Select
            $ObjWord.Selection.Text = $XPPW                                 
    Case $Type = 2
            $ObjWord.Activedocument.Bookmarks("Text8").Select
            $ObjWord.Selection.Text = $SapID
            $ObjWord.Activedocument.Bookmarks("Text9").Select
            $ObjWord.Selection.Text = $SAPPW
    Case $Type = 3                                                                                          
            $ObjWord.Activedocument.Bookmarks("Text6").Select
            $ObjWord.Selection.Text = $UserID                                                                                           
            $ObjWord.Activedocument.Bookmarks("Text7").Select
            $ObjWord.Selection.Text = $XPPW                                 
            $ObjWord.Activedocument.Bookmarks("Text8").Select
            $ObjWord.Selection.Text = $SapID
            $ObjWord.Activedocument.Bookmarks("Text9").Select
            $ObjWord.Selection.Text = $SAPPW
EndSelect       

$objWord.Activedocument.PrintOut.Background = False
$objWord.Activedocument.Close.SaveChanges = wdDoNotSaveChanges
Edited by Lempke
Link to comment
Share on other sites

This is my script

$objWord.Activedocument.Close.SaveChanges = wdDoNotSaveChanges
Last line, "wdDoNotSaveChanges", that has no $ symbol so is strange that an error does not warn you. I would guess it is ment to be a const variable?

You are comparing $Type (string) to 1, 2 or 3 (int) which is not good.

Link to comment
Share on other sites

Last line, "wdDoNotSaveChanges", that has no $ symbol so is strange that an error does not warn you. I would guess it is ment to be a const variable?

You are comparing $Type (string) to 1, 2 or 3 (int) which is not good.

I'll Look into that.

My main problem is that it doesn't work unvisible and the strange output.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...