Jump to content
Valnurat

Change fontsize and set bold in Excel

Recommended Posts

Valnurat

How do you set the font size and bold on text in excel by using Autoit?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

Please check the wiki :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

I did and maybe I don't understand it.

But I have this code:

Local $oAppl = _Excel_Open(True, True, True, True, True)
If @error Then Exit MsgBox(0x41000, "ERROR", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Sleep(500)
Local $oWorkbook = _Excel_BookNew($oAppl)
If @error Then
    MsgBox(0x41000, "ERROR", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oAppl)
    Exit
EndIf
Sleep(500)

_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'Name', 'A1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'email', 'B1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'company', 'C1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'Organisational belonging', 'D1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'Country', 'E1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'Main Local Site', 'F1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'Job Title', 'G1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'Description', 'H1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, 'Manager', 'I1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
with $oWorkbook.Activesheet.range(A1:I1).font
    .select
    .bold = True
EndWith

_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aMail, 'A2')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;Sleep(500)
_Excel_RangeSort($oWorkbook, $oWorkbook.Activesheet, 'A:I', 'A2', $xlAscending, $xlSortNormal, $xlYes)
If @error Then Exit MsgBox(0x41000, "ERROR", "Error sorting data." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
If WinActive('Book1 - Excel') Then Send('^a!hoi^{HOME}')

In the "With...EndWith

 

I get an syntax error

A1(): undefinded fuction

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

Try this:

#include <excel.au3>
Local $oAppl = _Excel_Open(True, True, True, True, True)
If @error Then Exit MsgBox(0x41000, "ERROR", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookNew($oAppl)
If @error Then
    MsgBox(0x41000, "ERROR", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oAppl)
    Exit
EndIf
Global $aHeader[1][9] = [['Name', 'email', 'company', 'Organisational belonging', 'Country', 'Main Local Site', 'Job Title', 'Description', 'Manager']]
Global $aMail[1]
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aheader, 'A1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oWorkbook.Activesheet.range("A1:I1").font.bold = True
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aMail, 'A2')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_RangeSort($oWorkbook, $oWorkbook.Activesheet, 'A:I', 'A2', $xlAscending, $xlSortNormal, $xlYes)
If @error Then Exit MsgBox(0x41000, "ERROR", "Error sorting data." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

What do you try to do with this line?

If WinActive('Book1 - Excel') Then Send('^a!hoi^{HOME}')

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

Thank that worked.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
Valnurat

What do you try to do with this line?

If WinActive('Book1 - Excel') Then Send('^a!hoi^{HOME}')

 

I want to set the size of the column to match the content so it is readable.

Try this:

#include <excel.au3>
Local $oAppl = _Excel_Open(True, True, True, True, True)
If @error Then Exit MsgBox(0x41000, "ERROR", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookNew($oAppl)
If @error Then
    MsgBox(0x41000, "ERROR", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oAppl)
    Exit
EndIf
Global $aHeader[1][9] = [['Name', 'email', 'company', 'Organisational belonging', 'Country', 'Main Local Site', 'Job Title', 'Description', 'Manager']]
Global $aMail[1]
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aheader, 'A1')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oWorkbook.Activesheet.range("A1:I1").font.bold = True
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aMail, 'A2')
If @error Then Exit MsgBox(0x41000, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_RangeSort($oWorkbook, $oWorkbook.Activesheet, 'A:I', 'A2', $xlAscending, $xlSortNormal, $xlYes)
If @error Then Exit MsgBox(0x41000, "ERROR", "Error sorting data." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

 

Thank you that worked.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

I want to set the size of the column to match the content so it is readable.

This code sets columns A:I to autofit.

$oWorkbook.Activesheet.Range("A:I").Columns.Autofit

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

This code sets columns A:I to autofit.

$oWorkbook.Activesheet.Range("A:I").Columns.Autofit

 

I guess there is a lot of tricks. Where do I see these tricks?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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

  • Similar Content

    • smud
      By smud
      Currently, I'm working on a program that will display Dialog boxes with either Yes or No.
      For each dialog, I reward the user with X amount of Credits.
      I'm hoping to output the amount of credits to a cell in a column (there will be 20 different columns).
      It will only post to a row that is equal to today's date (first column). If no row exists yet with the current date, it will start a new row.
      Any suggestions?
      Thank you
    • nooneclose
      By nooneclose
      How do I properly convert this to Autoit? This is a VBA macro that I recorded in Excel.
       ActiveSheet.Outline.ShowLevels RowLevels:=2 I need this to close my subtotal once it is finished. 
      any help will be greatly appreciated. 
    • Skeletor
      By Skeletor
      Hi All,
      While creating a few excel spreadsheets using AutoIt, I came across something which to my limiting time to research the forums I don't anyone has mentioned. 
      The color pallettes are reversed. 
      Huge shock to me.
       
      I wanted to produce a red row but kept on getting blue. 
      Seems like 0xFF0000 was red on the charts but when running the script, I got blue. 
      I then played around with the colors, and after a few tries, I finally got Red. 
      Reversed the FF0000 and the result is 0000FF.
       
      So for Excel compared to Html
      0000FF (Red) - Excel
      0000FF (Blue) - Html

      FFFF00 (Cyan) - Excel
      FFFF00(Yellow) - Html
       
    • Jemboy
      By Jemboy
      Yesterday I had to make some little changes to an old Autoit program we use at my work.
      The program reads some data and convert it to Excel.
      Before writing the cell, it is changed to text and later on I slap the column with an autofitwidth.
      Furthermore weI execute a conditional format on the sheet, to make the data more readable.
      I quickly found out that because of the breaking changes Excel.udf had starting from AutoIt 3.3.12.0,
      a lot of things had to been changed.
      The changes I had to do, only took 10 minutes.
      After trying to adjust the script for over 5 hours, to get it working with the new Excel.udf, I gave up.
      I stopped changing the script, uninstalled the my Autoit and went looking for an older version.
      Luckilly I was able to find Autoit v3.3.8.1 (with corresponding Scite) in my software repository.
      Installing Autoit V3.3.8.1 and compiling the file, now took me  10 minutes .
       
      So why did I not get the old script working with the new Excel.udf?
      There are several reasons I failed getting the old script working with the new Excel UDF.
       I had some pressure from management to fix it ASAP (and got a little anxious)  Most all resources on the internet point to the working of the old EXcel.UDF And offcourse there were thosing "breaking changes",
      with new functions using diffrent parameters or using parameters in different order. One of the column's on the sheet is used to store EAN13 (barcode) and was formatted like 1,23E12.
      I couldn't change the cell to text, also autofitwidt was not working and using conditional formatting was also a no-no.
      So in the end I could use the new Excel UDF, but not desapointed management.
       
      What would I like to ask?
      I understand that sometimes you want to rewrite a program to make it better. I even understand that one has to make breaking changes sometimes.
      But in this case because of lacking examples/resources my day went completely down the drain.
      I would like to ask the Excel.udf developpers to:
      Make more functions available to do things like changing cell properties easily, changing cell color, do an autofit columnwidth, format data conditionally. 
        Or write an Example using the (new) Excel UDF, making examples how to format a cell, do conditional format, changing cell colors etc.
        I probably am more of an example guy.
      Having a good Excel.UDF Example showing a lot of common things normally makes, programming things easy for me.
      Because I can keep tweaking snippets until I get it working the way I want it.
       
      So dear developpers, could you help me and other future user out?
       
       
       
       
       
       
       
       
       
       
       
       
       
       
    • Moonscarlet
      By Moonscarlet
      Hello,
      Suddenly, I am getting an error (@extended = -2147221164) when I try to open excel using:
      #include <Excel.au3> _Excel_Open() If @error Then MsgBox(0,"",@error &@CRLF &@extended) Can anyone help with this?
×