autoit excel manipulation

Hello Experts,

 I've had to ask this question again as the administrators closed off the original question before I could test out the answer.

 Hello MatrixNZ,
 I'm hoping that you can repost your proposed code as that looked to be spot on.

  I'm a programming noob and I am attempting to open an existing excel file with autoit, then populate specific cells with data and then closing the file with a new name.

  My attempt is as follows:


  ;CodeStart

  #include <ExcelCOM_UDF.au3>  ; Include the function collection

  Local $sFilePath = "C:\Prod"
  Local $sFileTempPath = "C:\Temp"
  Local $File1 = "File1.xls"
  Local $File2 = "File2.xls"

  Local $oExcel = _ExcelBookOpen(1)

   _ExcelWriteCell($oExcel, "26/11/2014", "G41")                        ; Write the current date to cell G41

   ; Now we save it into the temp directory; overwrite existing file if necessary
  _ExcelBookSaveAs($oExcel, $FileTempPath & "temp.xls", "xls", 0, 1)

  ; And finally we close out
  _ExcelBookClose($oExcel)

  ;CodeFinish

  It compiles successfully but does not seem to do anything.
  I do not get a temp file in the directory.

  Thanks in advance.

  Cheers,
  Joe
joedelapazAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SimonCommented:
Hi, are you determined to do this with autoit or would you be happy with an Excel template that does the same?

From what I can see you are opening a file, writing a date to a cell and then saving the file to the temp directory. Is that the process or am I missing something?
0
joedelapazAuthor Commented:
Hi Simon,
Here's the scenario.
I have received an excel form from a vendor. I in order to renew access for my guys, I/we have to fill out the form and submit it each month. The vendor then renews our access. Obviously, this is a painfully repetitive and silly process. All we really need to do is to automatically change the date on the form and email it to the vendor.
This gives us another month before we have to go through the same process again.

So the idea is to automatically open this spreadsheet each month, go to the appropriate cell and set a new application date. Then go to another cell and calculate application date plus 30 days. Then save the form and another script will automatically email it to the vendor.

This vendor form is full of macros and is heavily locked down. And as you can tell from their bureaucracy if we mess around with their form, they will reject it.

I'm happy to consider any workable option.

Cheers,
Joe
0
SimonCommented:
Hi Joe, I don't have autoit, so I can't help with that. Whether doing it in Excel VBA is the right option will depend on your environment and how automated you want this to be. I don't know if autoit can run scheduled tasks to make this process run completely unattended and whether that would be advisable or not.

Here's the basic code (that I'd put in my personal startup workbook and either link to a button or wrap with some date logic in an auto_open() macro to determine if today is a good day to send a renewal.

It opens the form, updates the two date fields, saves a copy of the workbook to the temp directory and then generates a draft email to a hard-coded recipient. To send instead of displaying draft email, just change .display to .send

Sub UpdateWorkbookAndEmail()
Dim objOutlook As outlook.Application

    Workbooks.Open Filename:="\\[Your Path Here]\EE.xlsx"
    Range("D4").Value = DateValue(Now)
    Range("D12").Value = DateAdd("m", 1, DateValue(Now()))
    Application.DisplayAlerts = False 'set this to false to suppress overwrite warning dialog
    ActiveWorkbook.SaveAs "C:\Temp\temp.xls", , , , , , , xlLocalSessionChanges
    Application.DisplayAlerts = True
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMailItem = objOutlook.CreateItem(0)
    With objMailItem
        .To = "sbrown15@nhs.net"
        .CC = ""
        .BCC = ""
        .Subject = "Monthly access renewal"
        .Body = "Hi, please see attached form"
        .Attachments.Add ActiveWorkbook.FullName
        .Display 'or .send
    End With
    Set objMailItem = Nothing
    Set objOutlook = Nothing
    ActiveWorkbook.Close False
End Sub

Open in new window

0
matrixnzCommented:
Just saw this reposted, fortunately still had the code in Scite.

Hope that helps.

Cheers

#include <Excel.au3>

;~ Source Directory - Note added "\"
	Global $SRC_FILEPATH = "C:\Prod\"
;~ Check if Source Directory Exists, create the directory if false
	If FileExists($SRC_FILEPATH) = 0 Then DirCreate($SRC_FILEPATH)
;~ Temp Directory - Note added "\"
	Global $TMP_FILEPATH = "C:\Temp\"
;~ Check if Temp Directory Exists, create the directory if false
	If FileExists($TMP_FILEPATH) = 0 Then DirCreate($TMP_FILEPATH)
;~ First XLS WorkBook to Open
	Global $File1 = "File1.xls"
;~ Second XLS WorkBook to Open
	Global $File2 = "File2.xls"

;~ Attempt to open Source Directory\First XLS WorkBook
	Global $oExcel = _ExcelBookOpen($SRC_FILEPATH & $File1)
	;~ If unable to open the WorkBook or the File does not exist, open Excel with a Blank Excel WorkBook
	If @error = 1 Or @error = 2 Then
		$oExcel = _ExcelBookNew ()
	EndIf
;~ Write Cell to G41
	_ExcelWriteCell($oExcel, "26/11/2014", "G41")
;~ Save the WorkBook as Temp Directory\Second XLS WorkBook
	_ExcelBookSaveAs($oExcel, $TMP_FILEPATH & $File2, "xls", 0, 1)
;~ Close Excel WorkBook
	_ExcelBookClose($oExcel)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
joedelapazAuthor Commented:
Thanks Matrix. That did the trick! Cheers.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.