PDA

View Full Version : application not visible flashes



fgarcia90
07-13-2012, 09:18 AM
I have a VBA project with the application as not visible and when we open the file it flashes with excel... is there any way not to flash an go straight to one form??

thanks in advanced

CodeNinja
07-13-2012, 09:34 AM
Have you tried turning application.ScreenUpdating = False?

I guess the other question is where are you turning the application.visible = false?

fgarcia90
07-13-2012, 09:37 AM
is when it started:




Private Sub Workbook_Open()
Application.Visible = False


Module1.seccao

End Sub


but then goes to check the user and show a 1st form and during that time it flashes excel :(

CodeNinja
07-13-2012, 11:44 AM
Ok, this one is a bit trickier... You have to save the application invisible for it to come up next time without flashing the excel sheets. The problem with that is, accessing it again can be quite difficult, so I recommend a way for you to make application visible so you can get to the code etc...

The other work around is to call the application from some other program
(word, outlook, etc) and call it visible = false.


I used the following, with a userform that has a command button that when I click the command button it makes the form visibile. This way, I have an application that loads invisible, but I can make it visible. I do see the blue screen of the application, but I do not get any of the sheets to flash.

Private Sub Workbook_Open()
Application.Visible = False
ThisWorkbook.Save
UserForm1.Show

End Sub


' in userform commandbutton1click:
Private Sub CommandButton1_Click()
Application.Visible = True
End Sub

fgarcia90
07-13-2012, 12:36 PM
ok first I didn't explain my self totally correct...
I don't see the sheets flashing, just when I start I see as you pointed the blue screen when starts... and is there any other way without starting from other application?
if not, do I any ideia if I send the shortcut thru outlook as a task to others if it flashes too?

thanks in advanced

CodeNinja
07-13-2012, 01:24 PM
I do not think there is any way to avoid the flash directly from excel, although I am certainly not the most experienced vba guy here.

fgarcia90
07-13-2012, 01:31 PM
:) me neither lool

is there anyone that knows....

GTO
07-14-2012, 01:18 AM
You may wish to attach the workbook, after replacing any sensitive data.

snb
07-14-2012, 03:22 AM
Just 1 method:

open excel.
open your application with this code


sub snb()
with getobject("G:\OF\garcia.xls")
.save
.close false
end with
end sub


Now start your application from whereever.

fgarcia90
07-14-2012, 01:32 PM
well what you gave is that now excel open's the file without showing anything, saves and closes the file and let excel open without any sheet.

lucky I've made a copy just in case :)

restarting...

I have a xlsm file that when opens flashes excel and I don't wanto to open from other program and don't want to see even excel flash at start because in the end of the program I will change the icon of the file and so no one will dream it as the base of excel :)

GTO
07-14-2012, 03:44 PM
...
I have a xlsm file that when opens flashes excel and I don't wanto to open from other program and don't want to see even excel flash at start because in the end of the program I will change the icon of the file and so no one will dream it as the base of excel :)

Hi There,

I am still not utterly sure of what it is exactly that you are wanting to do, but see if this is at least in the right direction:

Before the user opens this one workbook(file), there are no instances (or at least no visible instances) of Excel currently running. Thus, the user is presumably opening the file (and starting Excel) by double-clicking the file in a windows explorer window.

If that is anywhere near the mark, then there is no way to prevent Excel from initially appearing/visible as the file opens, as long as the code resides only in the file/workbook of interest. Think of it this way: The highest "level" that code could start at within Excel - is the Application level; and creating a "Before the Application Instance Exists" event is physically impossible.

You could probably write a short .vbs script to start an instance of Excel, keeping the instance's .Visible property False, and open the file in this instance.

Hope that helps,

Mark

fgarcia90
07-14-2012, 04:47 PM
GTO you are complety in my direction, but I don't know .vbs scripts and instances that you refer.
Wanna brief me?
:)

GTO
07-14-2012, 09:49 PM
Hi There,

I am sure you will be able to find better examples of script files, but for a simple example, see attached.

Just to show the steps:

Create a folder to hold both the workbook and the .vbs script.

Create a text file and add:


Call Main()

Sub Main()
Dim FSO
Dim WshShell
Dim XL
Dim Path

Const FILENAME = "IamAninja.xls"

Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Path = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, "\"))
'WshShell.PopUp Path, 5, vbNullString, 64 Or 1

If Not FolderExists(FSO, Path) then
WshShell.PopUp "Folder was not found. Now exiting.", 6, "Error: Path not found.", 64
Exit Sub
ElseIf Not FileExists(FSO, Path & FILENAME) then
WshShell.PopUp FILENAME & " was not found. Now exiting.", 6, "Error: Path not found.", 64
Exit Sub
End If

Set XL = WScript.CreateObject("Excel.Application")
With XL
.Visible = FALSE
xl.Workbooks.Open Path & FILENAME
End With

Set WshShell = Nothing
Set FSO = Nothing
WScript.Quit
End Sub

Function FolderExists(ByRef fs, ByVal Path)
If fs.FolderExists(Path) then
FolderExists = TRUE
Else
FolderExists = FALSE
End If
End Function

Function FileExists(ByRef fs, ByVal FileName)
If fs.FileExists(FileName) then
FileExists = TRUE
Else
FileExists = FALSE
End If
End Function


Save, close, and change the text file's extension to '.vbs', like 'Run.vbs'.

Create a workbook in the same folder, naming it: IamAninja.xls

Create a UserForm in the workbook, default named to 'UserForm1'.

In the UserForm:
Create one TextBox, naming it: txtInput
Create a CommandButton, naming it: cmdAddValue
Create another CommandButton, naming it: cmdSaveAndExit

In the UserForm's Module, add:
Option Explicit

Private Sub cmdAddValue_Click()
Dim rngLastCellFound As Range

With Sheet1
Set rngLastCellFound = RangeFound(.Columns(1).Cells)
If rngLastCellFound Is Nothing Then
Set rngLastCellFound = .Columns(1).Cells(1)
End If

rngLastCellFound.Offset(1).Value = Me.txtInput.Value
Me.txtInput.Value = vbNullString
End With
End Sub

Private Sub cmdSaveAndExit_Click()
Me.Hide
If Not ThisWorkbook.Saved Then ThisWorkbook.Save
Unload Me
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'// NOT well tested, but I think this should "catch" dismissing the userform //
'// regardless of how, and not leave the application instance running hidden. //
Application.Quit
End Sub

Private Function RangeFound(SearchRange As Range, _
Optional ByVal FindWhat As String = "*", _
Optional StartingAfter As Range, _
Optional LookAtTextOrFormula As XlFindLookIn = xlValues, _
Optional LookAtWholeOrPart As XlLookAt = xlPart, _
Optional SearchRowCol As XlSearchOrder = xlByRows, _
Optional SearchUpDn As XlSearchDirection = xlPrevious, _
Optional bMatchCase As Boolean = False _
) As Range

If StartingAfter Is Nothing Then
Set StartingAfter = SearchRange(1)
End If

Set RangeFound = SearchRange.Find(What:=FindWhat, _
After:=StartingAfter, _
LookIn:=LookAtTextOrFormula, _
LookAt:=LookAtWholeOrPart, _
SearchOrder:=SearchRowCol, _
SearchDirection:=SearchUpDn, _
MatchCase:=bMatchCase)
End Function


In the ThisWorkbook Module:
Option Explicit

Private Sub Workbook_Open()
UserForm1.Show vbModal
End Sub


Now, when you double-click 'Run.vbs' in Windows Explorer, the script will create a hidden instance of Excel, and open the workbook in this instance.

Hope that helps,

Mark

snb
07-15-2012, 02:24 AM
well what you gave is that now excel open's the file without showing anything, saves and closes the file and let excel open without any sheet.

lucky I've made a copy just in case :)


1. you can always show the file using the ribbon, view, unhide teh file.
2. apparrently you din't code the opening of the userformin the workbook open event. If you had used


Private Sub Workbook_open()
userform1.show
end Sub


You would have got exactly what you are looking for.

fgarcia90
07-16-2012, 12:38 AM
No but I used this...


Private Sub Workbook_Open()
Application.Visible = False

user_passa_a_seccao.seccao

End Sub

so I thought that like this it could be enough not to flash at start :(


And GTO your litle test works but if the does not "opens" .vbs 1st or if it opens and closes the excel file one time it apears excel open...

GTO
07-16-2012, 04:36 AM
No but I used this...


Private Sub Workbook_Open()
Application.Visible = False

user_passa_a_seccao.seccao

End Sub

so I thought that like this it could be enough not to flash at start

Uhmmm... If I am understanding at all, you are not going to start the app hidden from a file that uses the app to open it.



And GTO your litle test works but if the does not "opens" .vbs 1st or if it opens and closes the excel file one time it apears excel open...

I am afraid you have quite lost me, as I do not understand what you are trying to relay.

Mark