Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default opening worksheet from VB

I'm opening Excel workbook from MS Access. The program
checks whether the file is opened. When the file is not
opened, it's working good enough. But, when it's opened,
after a user click Ok for macros and read-only, it appears
for a moment and disappears.

Could anybody advise anything?

Thanks

Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim strFileName As String, _
logFileIsOpened As Boolean

strFileName = "Filename"
logFileIsOpend = False


Set xlApp = CreateObject("Excel.Application")
DoCmd.SetWarnings False
xlApp.DisplayAlerts = False
xlApp.AskToUpdateLinks = False

logFileIsOpened = FileLocked(strFileName)

If logFileIsOpened = True Then
Set xlBook = GetObject(strFileName)
Set xlSheet = xlBook.Worksheets(strRecipeNum)

xlSheet.Activate
DoCmd.SetWarnings True
xlBook.Application.DisplayAlerts = True

xlBook.Application.AskToUpdateLinks = True
xlBook.Application.Visible = True
xlSheet.Visible = xlSheetVisible

Else
Set xlBook = xlApp.Workbooks.Open(strFileName)
Set xlSheet = xlBook.Worksheets(strRecipeNum)
xlSheet.Activate
DoCmd.SetWarnings True
xlApp.DisplayAlerts = True
xlApp.AskToUpdateLinks = True
xlApp.Visible = True
xlSheet.Visible = xlSheetVisible
End If



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default opening worksheet from VB

Thanks,
It looks like I've resolved it by using MyXL as Object and
API functions from the help file for GetObject

Alex

Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim xlSheet As Excel.Worksheet
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
Set xlSheet = MyXL.Worksheets(strNumber)

xlSheet.Activate
DoCmd.SetWarnings True
MyXL.Application.DisplayAlerts = True

MyXL.Application.AskToUpdateLinks = True
MyXL.Application.Visible = True
xlSheet.Visible = xlSheetVisible

-----Original Message-----
I'm opening Excel workbook from MS Access. The program
checks whether the file is opened. When the file is not
opened, it's working good enough. But, when it's opened,
after a user click Ok for macros and read-only, it

appears
for a moment and disappears.

Could anybody advise anything?

Thanks

Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim strFileName As String, _
logFileIsOpened As Boolean

strFileName = "Filename"
logFileIsOpend = False


Set xlApp = CreateObject("Excel.Application")
DoCmd.SetWarnings False
xlApp.DisplayAlerts = False
xlApp.AskToUpdateLinks = False

logFileIsOpened = FileLocked(strFileName)

If logFileIsOpened = True Then
Set xlBook = GetObject(strFileName)
Set xlSheet = xlBook.Worksheets(strRecipeNum)

xlSheet.Activate
DoCmd.SetWarnings True
xlBook.Application.DisplayAlerts = True

xlBook.Application.AskToUpdateLinks = True
xlBook.Application.Visible = True
xlSheet.Visible = xlSheetVisible

Else
Set xlBook = xlApp.Workbooks.Open(strFileName)
Set xlSheet = xlBook.Worksheets(strRecipeNum)
xlSheet.Activate
DoCmd.SetWarnings True
xlApp.DisplayAlerts = True
xlApp.AskToUpdateLinks = True
xlApp.Visible = True
xlSheet.Visible = xlSheetVisible
End If



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening worksheet Judy Excel Discussion (Misc queries) 1 February 9th 09 01:55 PM
opening worksheet maui172 Excel Discussion (Misc queries) 1 March 27th 08 11:23 PM
Opening a worksheet ssigler Excel Discussion (Misc queries) 1 May 12th 06 08:16 PM
VBA Opening worksheet, name changes Jeff Excel Discussion (Misc queries) 5 September 20th 05 06:00 PM
Opening a worksheet in VBA gwgeller Excel Programming 3 January 28th 04 07:06 PM


All times are GMT +1. The time now is 01:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"