OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Macro cannot access data in files opened in invisible mode?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
MacroMeow
General User
General User


Joined: 07 Jan 2012
Posts: 9

PostPosted: Tue Feb 07, 2012 6:34 pm    Post subject: Macro cannot access data in files opened in invisible mode? Reply with quote

My macro opens two spreadsheets (a database and a record file), then based on user input, grabs an entry from the database, selects a sheet in the record file and pastes the entry into the selected sheet.

After I made both spreadsheets open in invisible mode, my macro seems unable to find the selected sheet in the record file. I checked that it works when the spreadsheets are not opened in invisible mode.

I thought invisible mode means invisible only to the user, but the macro can still read from and write to the invisible files (assuming they are not read-only or password-protected)? How can I get the macro to read from the database and write to the record file, without letting the user see either spreadsheet?

How to close invisible files? After I got the error and edited the open settings, I ran the macro again but both spreadsheets opened in read-only mode.
Back to top
View user's profile Send private message
probe1
Moderator
Moderator


Joined: 18 Aug 2004
Posts: 2560
Location: Chonburi Thailand Asia

PostPosted: Tue Feb 07, 2012 6:39 pm    Post subject: Re: Macro cannot access data in files opened in invisible mo Reply with quote

MacroMeow wrote:
I thought invisible mode means invisible only to the user

This should be so.

MacroMeow wrote:
How to close invisible files?

Same way you close visible ones.
Delete the file lock to have them opened r/w again.


Which OOo version?
Which operating system?
Can you show some code...?
_________________
Cheers
Winfried
My Macros
DateTime2 extension: insert date, time or timestamp, formatted to your needs
Back to top
View user's profile Send private message Visit poster's website
MacroMeow
General User
General User


Joined: 07 Jan 2012
Posts: 9

PostPosted: Tue Feb 07, 2012 7:18 pm    Post subject: Reply with quote

Using OpenOffice 2.3 on Windows XP.

Most of the code is as follows (some code hidden and some variables renamed to avoid information security breaches):

Code:

Rem Declare values for RecordFileName and DatabaseFileName
Dim RecordingProps(0) as New com.sun.star.beans.PropertyValue
RecordingProps(0).Name = "Hidden"
RecordingProps(0).Value = "True"
Dim DatabaseProps(0) as New com.sun.star.beans.PropertyValue
DatabaseProps(0).Name = "Hidden"
DatabaseProps(0).Value = "True"
StarDesktop.loadComponentFromURL(RecordFileName, "blank_", 0, RecordingProps())
Dim RecordingFile
RecordingFile = ThisComponent
StarDesktop.loadComponentFromURL(DatabaseFileName, "blank_", 0, DatabaseProps())
Dim DatabaseFile
DatabaseFile = ThisComponent
TheDatabase = ThisComponent.Sheets(0)
Dim DetailsValid
DetailsValid = True
Dim FindSpace as Integer
Dim SheetName as String
Dim DBEntry as String
Rem Declare values for EnterMsg.
Do
 If DetailsValid = True Then
  EnterDetails = InputBox(EnterMsg)
 Else
  EnterDetails = InputBox (ErrorMsg)
 End If
 If EnterDetails = "" Then
  Exit Sub
 Else
  FindSpace = InStr(EnterDetails, " ")
 End If
 If FindSpace = 0 Then
  DetailsValid = False
  ErrorMsg = "You only entered one word! Please try again or click Cancel."
 Else
  SheetName = Left(EnterDetails, FindSpace - 1)
  DBEntry = Right(EnterDetails, Len(EnterDetails) - FindSpace)
   If RecordingFile.Sheets.hasByName(SheetName) Then
    RecordingSheet = RecordingFile.Sheets.getByName(SheetName)
    Rem Search for DBEntry in DatabaseFile. If found, records. If not, DetailsValid = False and ErrorMsg = "Could not find database entry. Please try again or click Cancel."
   Else
    DetailsValid = False
    ErrorMsg = "Could not find sheet to record to. Please try again or click Cancel."
   End If
 End If
Loop Until DetailsValid = True
RecordingFile.store()
DatabaseFile.close(True)
MonitorFile.close(True)


I get the "Could not find sheet to record to. Please try again or click Cancel." message.

However, when I change
Code:

Dim RecordingProps(0) as New com.sun.star.beans.PropertyValue
RecordingProps(0).Name = "Hidden"
RecordingProps(0).Value = "True"
Dim DatabaseProps(0) as New com.sun.star.beans.PropertyValue
DatabaseProps(0).Name = "Hidden"
DatabaseProps(0).Value = "True"


to

Code:

Dim RecordingProps() as New com.sun.star.beans.PropertyValue
Dim DatabaseProps() as New com.sun.star.beans.PropertyValue


the macro works like a charm, except that the files are visible.
Back to top
View user's profile Send private message
probe1
Moderator
Moderator


Joined: 18 Aug 2004
Posts: 2560
Location: Chonburi Thailand Asia

PostPosted: Tue Feb 07, 2012 8:02 pm    Post subject: Reply with quote

I've not tested your code, but try this:

Code:
RecordingFile  = StarDesktop.loadComponentFromURL(RecordFileName, "blank_", 0, RecordingProps())

DatabaseFile = StarDesktop.loadComponentFromURL(DatabaseFileName, "blank_", 0, DatabaseProps())


And:

I don't see DetailsValid = True within your IF construct.... (maybe a copy / paste problem?)
_________________
Cheers
Winfried
My Macros
DateTime2 extension: insert date, time or timestamp, formatted to your needs
Back to top
View user's profile Send private message Visit poster's website
MacroMeow
General User
General User


Joined: 07 Jan 2012
Posts: 9

PostPosted: Tue Feb 07, 2012 11:35 pm    Post subject: Reply with quote

It works! Thanks so much!

That means an invisible file cannot be ThisComponent?

Yes, DetailsValid = True was meant to be declared beforehand, so its value would only be changed to False if there was an error.
Back to top
View user's profile Send private message
probe1
Moderator
Moderator


Joined: 18 Aug 2004
Posts: 2560
Location: Chonburi Thailand Asia

PostPosted: Tue Feb 07, 2012 11:41 pm    Post subject: Reply with quote

MacroMeow wrote:
That means an invisible file cannot be ThisComponent?



F1 Help wrote:
Addresses the active component [...] ThisComponent is used from document Basic, where it represents the document the Basic belongs to


In your code -when opening a doc- it's whether active nor in Basic code attached to document.

Running visible changed ThisComponent to the just opened document - so it worked.
_________________
Cheers
Winfried
My Macros
DateTime2 extension: insert date, time or timestamp, formatted to your needs
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group