ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   open and activate workbook? (https://www.excelbanter.com/excel-programming/302847-re-open-activate-workbook.html)

Dave Peterson[_3_]

open and activate workbook?
 
In some minor testing, this only caused a problem for me if the worksheet window
was not maximized.

If I maximized the worksheet window, then opened a workbook that had its windows
minimized, it was opened maximized (did that make sense???).

So I could add a line before showing the dialog that maximizes the window:

ActiveWindow.WindowState = xlMaximized

Another option is to just open it and then maximize it. I like displaying the
getopenfilename dialog and controlling what happens later.

Option Explicit
Sub testme01()

Dim wkbk As Workbook
Dim myFileName As Variant

myFileName = Application.GetOpenFilename("Excel File, *.xls")

If myFileName = False Then
Exit Sub 'user hit cancel
End If

Set wkbk = Workbooks.Open(Filename:=myFileName)

wkbk.Windows(1).WindowState = xlMaximized

End Sub



schpank wrote:

I am using a dialog box to have the user select an open file, but if the file opened happens to be saved as minimized, it does not activate. I am just trying to copy some data from the opened file, then go back to the file with the macro to paste etc. Seems like there should be a way to reference the newly opened file and activate it? Or open it and activate it as one step? any help appreciated:
Application.Dialogs(xlDialogOpen).Show arg1:=""
Range("$A$1:$A$6").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
ThisWorkbook.Activate


--

Dave Peterson



All times are GMT +1. The time now is 01:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com