Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Using filename retrieved from GetOpenFilename

I am trying to write a macro that will use one file to update another. I got
some test code to work the way I wanted, but I need to user to select the
target file, and that is causing trouble.

Here is what I have so far:
Option Explicit
Sub auto_open()
Dim FileName As Variant
Application.ScreenUpdating = False
FileName =Application.GetOpenFilename(MultiSelect:=False)
Workbooks.Open FileName
Workbooks(FileName).Worksheets("Sheet1").Unprotect Password:="password"
ThisWorkbook.Worksheets("Sheet1").Activate
ActiveSheet.Cells.Copy
Workbooks(FileName).Worksheets("Sheet1").Range("A1 ").PasteSpecial
Workbooks(FileName).Worksheets("Sheet1").Activate
ActiveSheet.Range("A1").Select
Workbooks(FileName).Worksheets("Sheet1").Protect Password:="password"
Application.CutCopyMode = False
Application.ScreenUpdating = True
ThisWorkbook.Close savechanges:=False
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,081
Default Using filename retrieved from GetOpenFilename

Filename will include the path for the workbook - which is OK for opening the
file. After that, Excel dispenses with the path. Use something like this

Sub auto_open()
Dim FileName As Variant
Application.ScreenUpdating = False

FileName =Application.GetOpenFilename(MultiSelect:=False)
if filename = false then exit sub
dim wb as workbook
set wb = Workbooks.Open (FileName)
wb.Worksheets("Sheet1").Unprotect Password:="password"

ThisWorkbook.Worksheets("Sheet1").Activate
ActiveSheet.Cells.Copy
wb.Worksheets("Sheet1").Range("A1").PasteSpecial
wb.Worksheets("Sheet1").Activate
ActiveSheet.Range("A1").Select
wb.Worksheets("Sheet1").Protect Password:="password"
Application.CutCopyMode = False
Application.ScreenUpdating = True
ThisWorkbook.Close savechanges:=False
End Sub



"Horatio J. Bilge, Jr." wrote:

I am trying to write a macro that will use one file to update another. I got
some test code to work the way I wanted, but I need to user to select the
target file, and that is causing trouble.

Here is what I have so far:
Option Explicit
Sub auto_open()
Dim FileName As Variant
Application.ScreenUpdating = False
FileName =Application.GetOpenFilename(MultiSelect:=False)
Workbooks.Open FileName
Workbooks(FileName).Worksheets("Sheet1").Unprotect Password:="password"
ThisWorkbook.Worksheets("Sheet1").Activate
ActiveSheet.Cells.Copy
Workbooks(FileName).Worksheets("Sheet1").Range("A1 ").PasteSpecial
Workbooks(FileName).Worksheets("Sheet1").Activate
ActiveSheet.Range("A1").Select
Workbooks(FileName).Worksheets("Sheet1").Protect Password:="password"
Application.CutCopyMode = False
Application.ScreenUpdating = True
ThisWorkbook.Close savechanges:=False
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Using filename retrieved from GetOpenFilename

Nice simple fix. Thanks for the help.


"Duke Carey" wrote:

Filename will include the path for the workbook - which is OK for opening the
file. After that, Excel dispenses with the path. Use something like this

Sub auto_open()
Dim FileName As Variant
Application.ScreenUpdating = False

FileName =Application.GetOpenFilename(MultiSelect:=False)
if filename = false then exit sub
dim wb as workbook
set wb = Workbooks.Open (FileName)
wb.Worksheets("Sheet1").Unprotect Password:="password"

ThisWorkbook.Worksheets("Sheet1").Activate
ActiveSheet.Cells.Copy
wb.Worksheets("Sheet1").Range("A1").PasteSpecial
wb.Worksheets("Sheet1").Activate
ActiveSheet.Range("A1").Select
wb.Worksheets("Sheet1").Protect Password:="password"
Application.CutCopyMode = False
Application.ScreenUpdating = True
ThisWorkbook.Close savechanges:=False
End Sub



"Horatio J. Bilge, Jr." wrote:

I am trying to write a macro that will use one file to update another. I got
some test code to work the way I wanted, but I need to user to select the
target file, and that is causing trouble.

Here is what I have so far:
Option Explicit
Sub auto_open()
Dim FileName As Variant
Application.ScreenUpdating = False
FileName =Application.GetOpenFilename(MultiSelect:=False)
Workbooks.Open FileName
Workbooks(FileName).Worksheets("Sheet1").Unprotect Password:="password"
ThisWorkbook.Worksheets("Sheet1").Activate
ActiveSheet.Cells.Copy
Workbooks(FileName).Worksheets("Sheet1").Range("A1 ").PasteSpecial
Workbooks(FileName).Worksheets("Sheet1").Activate
ActiveSheet.Range("A1").Select
Workbooks(FileName).Worksheets("Sheet1").Protect Password:="password"
Application.CutCopyMode = False
Application.ScreenUpdating = True
ThisWorkbook.Close savechanges:=False
End Sub


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
Can the author of an .XLS be found and retrieved ? HTTC guy Excel Discussion (Misc queries) 1 July 14th 06 05:01 PM
GetOpenFilename not returning a usable variable Lilivati Excel Discussion (Misc queries) 2 June 26th 06 09:02 PM
vlookup with more than number to be retrieved martelie Excel Worksheet Functions 3 October 14th 05 12:50 PM
vlookup with more than number to be retrieved martelie Excel Worksheet Functions 1 October 8th 05 07:33 AM
Filter Count of Records Retrieved. amkazen Excel Discussion (Misc queries) 2 March 31st 05 10:03 PM


All times are GMT +1. The time now is 05:34 PM.

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"