Does a VBA module in Excel treated as a spreadsheet in NPOI or POI? - npoi

I am working on a NPOI project.
I have an Excel file which contains 5 spread sheets out of which:
2 are hidden (as they are dialog, user interface, kind of sheets DlgView1, DlgView2).
3 work sheets (WrkSht1, WrkSht2, WrkSht3) are visible with some data containing formulas and external links.
Also, the Excel sheet contains a VBA module called Module1.bas with some logic.
When I check the number of worksheets using workbook.NumberOfSheets property, it shows 5, but when I iterate through the code for all worksheets present, I get the below results:
1. Sheet1 = DlgView1 -------> which is hidden
2. Sheet2 = DlgView2 -------> which is hidden
3. Sheet3 = Module1 -------> which is hidden --->This is what is confusing!!!!
4. Sheet4 = WrkSht1 -------> which is visible
5. Sheet5 = WrkSht2 -------> which is visible
It should have been like this instead I suppose:
1. Sheet1 = DlgView1 -------> which is hidden
2. Sheet2 = DlgView2 -------> which is hidden
3. Sheet3 = WrkSht1 -------> which is visible
4. Sheet4 = WrkSht2 -------> which is visible
5. Sheet5 = WrkSht3 -------> which is visible
I cannot get access to one of the visible worksheet WrkSht3 as the count(= 5) of worksheet ends by this time.
Also, when my code sets to play around different cells of worksheet WrkSht1, it will actually be pointing to WrkSht2 and for worksheet WrkSht2, it will actually be pointing to WrkSht3.
But WrkSht3 was never initialzed as a worksheet as seen from the above results.
For testing purpose, I deleted Module1 and checked, it works fine with count as 5 and considering all the worksheets (DlgView1, DlgView2, WrkSht1, WrkSht2, WrkSht3) to process.
Also, to mention, I get an exception thrown while working with this file & not with any others:
Unsupported BOF found of type VBModule
My question is:
Does NPOI or POI treat a VBA module in a Excel sheet as a hidden worksheet?
If not, why is the code considering Module1 as worksheet and not the actual visible worksheet WrkSht3 as explained above.
If yes, is there a way to tell code not consider VBA Modules as worksheets and also actual visible worksheets like WrkSht3.
If needed, I can send the Excel sheet which I am working on. Thanks

Related

How to get content from field

I'm totally new to Base. I have different forms but in one named F_STRUCT of them I'm trying to make a macro which will allow the user to autofill another field when he select a zipcode.
so the database looks like this.
ID_ZIP ZIP CITY
1 97425 Les Avirons
2 82289 Toto
In my forms, I have a select which allows to select the ZIP code. It's label and name is ZipCode.
So I don't really know where to find the API reference for all the methods and chill methods, I followed examples from internet.
I tried this
Sub getZip
Dim Doc As Object
Dim DrawPage As Object
Dim Form As Object
Doc = StarDesktop.CurrentComponent
DrawPage = Doc.DrawPage
Form = DrawPage.Forms.GetByIndex(0)
Toto = Form.GetByName("ZipCode")
Print "hey"
End Sub
But it returns an error on the Toto = Form.GetByName("ZipCode") line.
The code works, so the problem must be how you created the form or control. Follow these instructions to set up a correct example:
Create Form in Design View
Use the List Box tool (is that what you mean by "select"?) and create a control.
Cancel out of the wizard if it pops up.
Right-click on the control and select Control Properties (not Name, which would modify the shape name instead of the control's name).
Set the Name to "ZipCode" (without quotes).
Save and close the form.
Open the form. In the window of that form (the CurrentComponent) go to Tools -> Macros -> Run Macro.
A list of documentation links for Base is at https://ask.libreoffice.org/en/question/80972/to-learn-libreoffice-base-are-there-introductions-or-tutorials/?answer=80973#post-id-80973.

Scrape data from ajax loaded table into excel using VBA

I've got a problem with one case that I want to resolve.
I've a web-page with 3 tables that are loaded by clicking the button (ajax response). User is selecting the date ranges and after button is clicked data is populated to tables.
What I want to do is to take those tables into excel using VBA, so within one click I can copy those tables from page to excel.
I've searched the internet, but didn't found something that regards to similar issue.
Currently I've macro to download those tables, but by default they are empty, so the code downloads only headers.
Option Explicit
Sub GetData()
Dim H As Object, B$, D As Object, C As Object
Set C = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
Set D = CreateObject("HTMLFile")
Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
H.SetAutoLogonPolicy 0
H.Open "GET", "https://mywebpage.com"
H.Send
D.body.innerHTML = H.ResponseText
C.SetText D.getElementById("table").outerHTML
C.PutInClipboard
Worksheets("sheet1").[A1].PasteSpecial
Worksheets("sheet1").Cells.Hyperlinks.Delete
End Sub
Does anyone have some idea how to call ajax function (with time parameters that are chosen in the page) from the excel visual basic?

Disabling workbookopen Event for XLSB file

I have the following issue:
I created an Excel sheet in XLSB format.
To protect that sheet, password generated by performing some operations on present month and year which would be a numeric value.
Used input box to get a password from the user in a string variable.
step 2 and 3 done in workbookopen event.
I closed the workbook and when again opened was prompted for the password which would never match even though I know the password.
What to do now? I have tried disabling macros but it doesn't seem to work.
finally tried following command
Application.EnableEvents = False
Which does exactly what i want but is not working for my sheet, though same is working fine for another trial sheet.
Sub disableCtrEvents()
Application.EnableEvents = False 'disable Events
Workbooks.Open "<path>\Wall area.xlsb"
Workbooks.Open "<path>\STAAD to steel drawing.xlsb"
End Sub
Following three files can be dowloaded from the link
test.xlsm - containing events disabling code (written above) and code to open other two sheets.
wall area.xlsb - trial sheet to check whether events are disabled or not.
STAAD to steel drawing.xlsb - actual file wherein i want to disable workbook open event
link - https://drive.google.com/open?id=1d_3Tu_-qIYErgYVkOjrCP4b8sZagXxF1

adding row manualy into DataGrid using VB6

i want to display the data into DataGrid manually in VB6, source of data is not from database or other source. I have created the column, like this:
For i = 2 To 4
DataGrid1.Columns.Add i
Next i
DataGrid1.Columns(0).Caption = "No"
DataGrid1.Columns(1).Caption = "Subdataset"
DataGrid1.Columns(2).Caption = "Dimension"
DataGrid1.Columns(3).Caption = "Check"
DataGrid1.Columns(3).Caption = "Detail"
but i can't add row and add value into it, i have tried like this:
Me.DataGrid1.AllowUserToAddRows = True
DataGrid1.Row = DataGrid1.Row + 1
then i got error
Please tell me if anybody can help me, thank you
Not only is DataGrid designed to be a bound control, it doesn't support unbound use. Says so right in the doc. So, the short answer is that you can't do what you are trying to do, because it's designed to display values from a database.
Instead, you'll want to use the MSFlexGrid control (Not the MSHFlexGrid control, although some of the doc confuses them), which you can read about here. Suppose you play around with that (the AddItem method is the fundamental piece you need to work with) and post back with specifics if you have problems.
Once you have added the table (DataGrid) right click select edit then you can insert columns:

Display a different image on combo box change in Access without file paths

I am creating a form that contains a combo box, lets say it's called 'Postcode_cb'. I want to have a unique image displayed for each of the items in that combo box. The images have to be in the same position and replace each other when the combo box is changed so that there is only ever 1 image. This has to be done without the use of file paths.
For example:
Try this way: create table [tblImg]([id], [picture]) where [id] is long and [picture] is OLE.
Insert two records with id=1 and id=2, embed corresponding images into [picture] field.
Then create stanalone form [frmImages] with rowsource [tblImg] and put 'bound object frame' with control source [picture].
Put [frmImages] as sub form at your main form.
Set LinkMasterFields to [Postcode_cb] and LinkChildFields to [id].
I have something like this on a database that gives out star rating of hotels. As you browse through the hotels it displays actual stars depending on the rating. The way that i did this was placed all the images in 1 spot (Placing them on top of one another) Give each image a name. and set them all to visible = no.
Example Img1, Img2 etc. until all images have a name.
Then open Visual basic and create a sub called Private Sub Form_Current() if you don't already have one. Then under this sub use the following Code
Forms![FormName]![ComboBoxName].SetFocus
Select Case Forms![FormName]![ComboBoxName].Text
Case Is = ""
Forms![FormName]!img1.Visible = False
Forms![FormName]!img2.Visible = False
Case Is = "1"
Forms![FormName]!img1.Visible = True
Case Is = "2"
Forms![FormName]!img2.Visible = True
End Select
This is only good if you only have something like 5 to 10 images anything more would be a lot harder to deal with in this way.
There maybe other ways people can suggest i found this the most easiest for my needs.

Resources