PC Review


Reply
Thread Tools Rate Thread

Difficulties Opening, copying from another workbook and closing

 
 
Corrie
Guest
Posts: n/a
 
      25th Oct 2007
I have the following script to open another workbook, copy certain
information, going back to the original macro driven workbook and then
closing the file source. It works okay, however it gets hung up for a
long period of time before the file closes. Any ideas what I'm doing
wrong?

Sub ImportUnusual()

Dim WorkbookName As String
Dim FileToOpen As String
Dim WorkbookName1 As String

Sheets("UnU DL").Select
Cells.Select
Selection.Clear
Selection.FormatConditions.Delete
Selection.Interior.ColorIndex = xlNone
Range("A1").Select
WorkbookName = Range("A1").Parent.Parent.Name
MsgBox "Please select the file with the inventory by customer data
you wish to import."
FileToOpen = Application _
.GetOpenFilename("Text Files (*.XLS), *.XLS")
If FileToOpen = "False" Then
End If
Workbooks.Open Filename:=FileToOpen
Range("A1").Select
WorkbookName1 = Range("A1").Parent.Parent.Name
Range("H3").Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows(WorkbookName).Activate
Windows(WorkbookName1).Close Savechanges:=False
Windows(WorkbookName).Activate
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
End Sub

 
Reply With Quote
 
 
 
 
Mike Fogleman
Guest
Posts: n/a
 
      25th Oct 2007
Try this:
Sub ImportUnusual()

Dim WorkbookName As String
Dim FileToOpen As String
Dim WorkbookName1 As String

Sheets("UnU DL").Cells.Clear
WorkbookName = ThisWorkbook.Name
MsgBox "Please select the file with the inventory by customer data you
wish to import."
FileToOpen = Application _
.GetOpenFilename("Text Files (*.XLS), *.XLS")
If FileToOpen = "False" Then
Exit Sub 'if no file selected
End If
Workbooks.Open Filename:=FileToOpen
WorkbookName1 = ActiveWorkbook.Name
Range("H3").Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy Workbooks(WorkbookName).Worksheets("UnU DL").Range("A1")
Windows(WorkbookName1).Close Savechanges:=False

End Sub

Mike F
"Corrie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have the following script to open another workbook, copy certain
> information, going back to the original macro driven workbook and then
> closing the file source. It works okay, however it gets hung up for a
> long period of time before the file closes. Any ideas what I'm doing
> wrong?
>
> Sub ImportUnusual()
>
> Dim WorkbookName As String
> Dim FileToOpen As String
> Dim WorkbookName1 As String
>
> Sheets("UnU DL").Select
> Cells.Select
> Selection.Clear
> Selection.FormatConditions.Delete
> Selection.Interior.ColorIndex = xlNone
> Range("A1").Select
> WorkbookName = Range("A1").Parent.Parent.Name
> MsgBox "Please select the file with the inventory by customer data
> you wish to import."
> FileToOpen = Application _
> .GetOpenFilename("Text Files (*.XLS), *.XLS")
> If FileToOpen = "False" Then
> End If
> Workbooks.Open Filename:=FileToOpen
> Range("A1").Select
> WorkbookName1 = Range("A1").Parent.Parent.Name
> Range("H3").Select
> Range(Selection, Selection.End(xlToLeft)).Select
> Range(Selection, Selection.End(xlDown)).Select
> Selection.Copy
> Windows(WorkbookName).Activate
> Windows(WorkbookName1).Close Savechanges:=False
> Windows(WorkbookName).Activate
> Range("A1").Select
> ActiveSheet.Paste
> Range("A1").Select
> End Sub
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can just opening & closing a workbook prompt the Save? dialog? baobob@my-deja.com Microsoft Excel Programming 4 26th May 2008 08:40 PM
Opening another workbook and then closing it. =?Utf-8?B?UGFzdHk=?= Microsoft Excel Programming 2 4th Apr 2007 10:20 AM
Re: Closing a workbook upon opening another Gord Dibben Microsoft Excel New Users 1 3rd Jan 2007 09:57 PM
opening & copying to a workbook mwc0914 Microsoft Excel Programming 0 18th Nov 2005 06:12 PM
running a specific macro on opening and closing a workbook kimt Microsoft Excel Misc 2 10th Feb 2004 12:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:11 PM.