Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Activating previously used workbook

Hi there,
I have a workbook which will have a different name with every changing day.
I am trying to import some data via VB and have maneged the import part but
since the name will change I can't activate the original file with
windows("XXX").activate... I have tried to save the name but I did not
succeed...
Any help would be great.

Thank you.

Ozgur
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Activating previously used workbook

Hi Ozgur,

can you work with the workbooks as with objects?

I mean:

dim wb1 as workbook
set wb1=workbooks.open filename:=(your original filename)


then you can activate your wb1 with wb1.activate.

Regards,
Ivan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Activating previously used workbook

Hi Ivan,
thanks for the reply.
I have a workbbok which has the following procedu

Sub Import()
Workbooks.Open Filename:="R:\DAILY\May06\daily.xls"
Range("A2:L2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Application.CutCopyMode = False
Windows("daily.xls").Close
Sheets(1).Select
Range("A2").Select
ActiveSheet.Paste
End Sub


My problem is that I can't use Windows("X").activate because the workbook
with the import macro will have a different name every time. Rather than
opening I need to find a way to activate the workbook from with the macro.

Ozgur


"Ivan Raiminius" wrote:

Hi Ozgur,

can you work with the workbooks as with objects?

I mean:

dim wb1 as workbook
set wb1=workbooks.open filename:=(your original filename)


then you can activate your wb1 with wb1.activate.

Regards,
Ivan


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Activating previously used workbook

Hi Ozgur,

if the procedure is in the workbook you need to activate, you can use:

thisworkbook.activate

if the workbook is different from that in which is the macro, you have
to create or open it, so you should be able to set it to object
variable.

But maybe I didn't understand you correctly.

Regards,
Ivan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Activating previously used workbook

Hi Ivan,
I am probably not very clear about the problem I face(sorry).
I tried thisworkbook.activate before but it did not work...

Last line activesheet.paste gives and error.

Sub Import()
Workbooks.Open Filename:="R:\treasury\DAILY\May06\daily.xls"
Range("A2:L2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Application.CutCopyMode = False
Windows("daily.xls").Close
ThisWorkbook.Activate
Sheets(1).Select
Range("A2").Select
ActiveSheet.Paste
End Sub

Thanks for your time.
Ozgur
"Ivan Raiminius" wrote:

Hi Ozgur,

if the procedure is in the workbook you need to activate, you can use:

thisworkbook.activate

if the workbook is different from that in which is the macro, you have
to create or open it, so you should be able to set it to object
variable.

But maybe I didn't understand you correctly.

Regards,
Ivan




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Activating previously used workbook

Hi Ozgur,

activesheet.paste gives you error probably because of
Application.CutCopyMode = False in your code. Try to comment it out.
Or:

Sub Import()
Workbooks.Open Filename:="R:\treasury\DAILY\May06\daily.xls"
Range("A2:L2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ThisWorkbook.Activate
Sheets(1).Select
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Windows("daily.xls").Close
End Sub

Regards,
Ivan

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Activating previously used workbook

Ivan,
its official you are a genious...:))

It worked.

Thanks a lot,
Ozgur

"Ivan Raiminius" wrote:

Hi Ozgur,

activesheet.paste gives you error probably because of
Application.CutCopyMode = False in your code. Try to comment it out.
Or:

Sub Import()
Workbooks.Open Filename:="R:\treasury\DAILY\May06\daily.xls"
Range("A2:L2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ThisWorkbook.Activate
Sheets(1).Select
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Windows("daily.xls").Close
End Sub

Regards,
Ivan


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
Open a workbook, Copy several cells, then Close the previously openedworkbook [email protected] Excel Worksheet Functions 0 April 9th 08 11:54 PM
activating a workbook VB Script for Excel Excel Programming 12 March 22nd 06 07:55 AM
Working within a workbook without activating it? hyyfte[_9_] Excel Programming 1 September 20th 04 03:34 PM
Open workbook without activating it Kelley[_2_] Excel Programming 3 October 29th 03 04:49 PM
Activating a workbook help bmwmcrider Excel Programming 1 October 21st 03 01:48 PM


All times are GMT +1. The time now is 04:25 AM.

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

About Us

"It's about Microsoft Excel"