#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default activating workbooks

I am trying to put some code together where I can copy a list of dates from
one file to another if they are different with the destination file name
having part of the file name varying from month to month.
This is what I have got so far but I get the message subscript out of range.

Sub Update_Ethane_Email_File()
If MthNum < 10 Then
Workbooks.Open Filename:="M:\KOLOPSMB\Post Conversion Files\Current
Year\0" & MthNum & " " & Left(MthName, 3) & " Data.xls", _
UpdateLinks:=0
Else
Workbooks.Open Filename:="M:\KOLOPSMB\Post Conversion Files\Current
Year\" & MthNum & " " & Left(MthName, 3) & " Data.xls", _
UpdateLinks:=0
End If
Workbooks.Open Filename:="M:\KOLOPSMB\Weekly and Monthly Emails\Ethane
Transfer Data " & MthName & ".xls", _
UpdateLinks:=0
Range("A5").Select
If ActiveCell.Value < DayOne Then
Windows("Create Email Notifications.xls").Activate
Range("Date_Field").Select
Selection.Copy
Windows("Ethane Transfer Data " & MthName & ".xls").Activate

End If
End Sub

Appreciate any help.

Thanks
Ray
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default activating workbooks

Some tweaks. This may help you figure out your problems.

Option Explicit

Sub Update_Ethane_Email_File()
Dim oWB As Excel.Workbook
Dim EthaneWB As Excel.Workbook
Dim aWB As Excel.Workbook
Dim aWS As Excel.Worksheet

Set aWB = ActiveWorkbook
Set aWS = ActiveSheet

If MthNum < 10 Then
On Error Resume Next
Set oWB = Workbooks.Open(Filename:= _
"M:\KOLOPSMB\Post Conversion Files\CurrentYear\0" & MthNum & " " &
Left(MthName, 3) & " Data.xls", _
UpdateLinks:=0)
On Error GoTo 0

Else
On Error Resume Next
Set oWB = Workbooks.Open(Filename:= _
"M:\KOLOPSMB\Post Conversion Files\CurrentYear\" & MthNum & " " &
Left(MthName, 3) & " Data.xls", _
UpdateLinks:=0)
On Error GoTo 0

End If
If oWB Is Nothing Then
MsgBox ("Workbook not opened")
End If

On Error Resume Next
Set EthaneWB = Workbooks.Open(Filename:= _
"M:\KOLOPSMB\Weekly and Monthly Emails\EthaneTransfer Data " & MthName &
".xls", _
UpdateLinks:=0)
'Range("A5").Select
On Error GoTo 0

If Not EthaneWB Is Nothing Then
If EthaneWB.ActiveSheet.Range("A5").Value < DayOne Then
'If this is the active worksheet, do this

aWS.Range("Date_Field").Copy
'Windows("Create Email Notifications.xls").Activate
'Range("Date_Field").Select

'This may not be needed
EthaneWB.Activate
End If
End If
End Sub




"Ray Clark" wrote:

I am trying to put some code together where I can copy a list of dates from
one file to another if they are different with the destination file name
having part of the file name varying from month to month.
This is what I have got so far but I get the message subscript out of range.

Sub Update_Ethane_Email_File()
If MthNum < 10 Then
Workbooks.Open Filename:="M:\KOLOPSMB\Post Conversion Files\Current
Year\0" & MthNum & " " & Left(MthName, 3) & " Data.xls", _
UpdateLinks:=0
Else
Workbooks.Open Filename:="M:\KOLOPSMB\Post Conversion Files\Current
Year\" & MthNum & " " & Left(MthName, 3) & " Data.xls", _
UpdateLinks:=0
End If
Workbooks.Open Filename:="M:\KOLOPSMB\Weekly and Monthly Emails\Ethane
Transfer Data " & MthName & ".xls", _
UpdateLinks:=0
Range("A5").Select
If ActiveCell.Value < DayOne Then
Windows("Create Email Notifications.xls").Activate
Range("Date_Field").Select
Selection.Copy
Windows("Ethane Transfer Data " & MthName & ".xls").Activate

End If
End Sub

Appreciate any help.

Thanks
Ray

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default activating workbooks

Barb,

Thank you, your information gave me enough code to solve my problem.

Thanks heaps.
Ray

"Ray Clark" wrote:

I am trying to put some code together where I can copy a list of dates from
one file to another if they are different with the destination file name
having part of the file name varying from month to month.
This is what I have got so far but I get the message subscript out of range.

Sub Update_Ethane_Email_File()
If MthNum < 10 Then
Workbooks.Open Filename:="M:\KOLOPSMB\Post Conversion Files\Current
Year\0" & MthNum & " " & Left(MthName, 3) & " Data.xls", _
UpdateLinks:=0
Else
Workbooks.Open Filename:="M:\KOLOPSMB\Post Conversion Files\Current
Year\" & MthNum & " " & Left(MthName, 3) & " Data.xls", _
UpdateLinks:=0
End If
Workbooks.Open Filename:="M:\KOLOPSMB\Weekly and Monthly Emails\Ethane
Transfer Data " & MthName & ".xls", _
UpdateLinks:=0
Range("A5").Select
If ActiveCell.Value < DayOne Then
Windows("Create Email Notifications.xls").Activate
Range("Date_Field").Select
Selection.Copy
Windows("Ethane Transfer Data " & MthName & ".xls").Activate

End If
End Sub

Appreciate any help.

Thanks
Ray

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
Activating links Tellu Excel Discussion (Misc queries) 2 August 25th 08 10:14 AM
Activating Function Nat Excel Worksheet Functions 7 September 27th 06 07:54 AM
Activating a Checkbox Lucille Excel Worksheet Functions 0 April 28th 06 06:22 PM
List box not activating sue74 Excel Discussion (Misc queries) 0 November 8th 05 01:34 PM
Activating a Hyperlink Jeremy S Excel Discussion (Misc queries) 3 July 3rd 05 02:15 AM


All times are GMT +1. The time now is 04:31 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"