Jump to content

Strange Problem in Excel


kcvinu
 Share

Recommended Posts

Hi all,
I am playing with an excel file. I wrote this function to insert some data from an array to excel sheet. Please look my code. When i run this, everything will br fine and i will get the MsgBox saying "Inserted". But then if you double click the excel file in script directory, you can't see the data. You can't even see the work book. Only excel will be opened. What is the problem ?. Any idea ?

This is my code

#include <Excel.au3>

Func ExcelInsertion()
    
    Local $sxlPath = @ScriptDir & "\Test.xlsx"
    Local $oxlObj = _Excel_Open(False)
    If @error Then MsgBox(0, "", "No Object Created" & @CRLF & @error)
    
    Local $oxlWB = _Excel_BookOpen($oxlObj,$sxlPath,False,False)
    If @error Then MsgBox(0, "","No Book is opened" & @CRLF & @error)
    
    Local $oxlSheet = $oxlWB.Worksheets("Sheet1")
    Local $aData = ["This is", "A Test", "To Insert","Data into", "Excel"]
    
    Local $iLastRow = $oxlSheet.UsedRange.Rows.Count
    For $i = 0 To 4
        $oxlSheet.Cells($iLastRow + 1, $i + 1).Value = $aData[$i]
    Next
    
    Local $save = _Excel_BookSave($oxlWB)
    _Excel_Close($oxlObj)
    MsgBox(0,"","Inserted")
    
EndFunc

ExcelInsertion()

For testing, i am providing the script file and the excel file here. 

New folder.zip

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Please check the remarks in _Excel_BookOpen. When you open a workbook invisible you have to make sure to make it visible again before saving. Else you get what you see now - nothing ;)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Correct me if i am wrong. I have opened a workbook invisible and did some work. Then i closed the book and the program. Then that game is over. I have tried to open the excel file right after closing the entire script. This is my thought. 

Edit = Anyways, problem solved. But i didn't understand properly. I am assuming that the script is setting this workbook up to permanantly invisible. 

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

As the help file says:

"When setting $bVisible = False when opening a Workbook make sure to set the Workbook to visible again before saving the Workbook.
Use $oExcel.Windows($oWorkbook.Name).Visible = True to make the Workbook visible again.
Else the Workbook will not be shown when you manually open it using Excel.
Most of the time this parameter is not needed. Using $bVisible = False in _Excel_Open is the preferred way."


This is not being reset when the workbook gets saved.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you @water

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

×
×
  • Create New...