Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Program calling up Excel - Not running Macro


I have a program that calls up excel and inserts in numbers for
reporting purposes. I do not have access to the program that does this.
The program itself will print off the report once the information is in
it. I have changed the template to include a macro that runs on the
BeforePrint event.

Basically all I am doing is creating a new workbook, or editing an old
one depending on circumstances. However, while the macro runs fine when
I test it. Somehow, when the program calls up the file, it does not
error out (I have yet to put in error protection) but will skip over
some of the key steps (i.e. Workbooks.Add or Workbooks.Open( SavePath &
NewBookName) will not actually take place, but the code will act like
it did. It also skips over

Here is the actual code I only know the steps that is skipping that are
making it fail, I do not know if there are other steps that it is
missing.


Function ConsolidateDBR()
Dim SitePath As String
Dim SiteNum As String
Dim NewBookName As String
Dim MonthlyBook As Workbook
Dim SavePath As String
Dim CurrentBook As Workbook
Dim Counter As Long
Dim tmpSheet As String
Dim NewBook As Boolean
NewBook = False
SitePath = ActiveWorkbook.Path
Set CurrentBook = Workbooks(ActiveWorkbook.Name)
If Right(SitePath, 1) = "\" Then
SitePath = Left(SitePath, Len(SitePath) - 1)
End If
NewBookName = "DBR" & Format(Cells(3, 26).Value, "yyyy-mmm") &
".xls"
SiteNum = Mid(SitePath, 7, Len(SitePath) - 6)
SavePath = "C:\DBR-Report"
MakeDirectory SavePath
If Right(SavePath, 1) < "\" Then
SavePath = SavePath & "\"
End If
If Dir$(SavePath & NewBookName) = "" Then
Set MonthlyBook = Workbooks.Add
NewBook = True
MonthlyBook.SaveAs SavePath & NewBookName, xlNormal
Else
Set MonthlyBook = Workbooks.Open(SavePath & NewBookName, , False)
End If
CurrentBook.Activate
Cells.Copy
With MonthlyBook
..Activate
Counter = 1
While .Sheets.Count = Counter
If .Sheets(Counter).Name = SiteNum Then
tmpSheet = SiteNum
End If
Counter = Counter + 1
Wend
If tmpSheet = "" Then
If NewBook = False Then
..Sheets.Add
End If
..ActiveSheet.Name = SiteNum
End If
..Sheets(SiteNum).Select
End With
Cells.PasteSpecial xlPasteAll
MonthlyBook.Save
MonthlyBook.Close
End Function
Function MakeDirectory(Directory As String)
On Error GoTo Created:
MkDir (Directory)
Created:
End Function

Thank you in advance for your help

-John


--
kraljb
------------------------------------------------------------------------
kraljb's Profile: http://www.excelforum.com/member.php...fo&userid=9955
View this thread: http://www.excelforum.com/showthread...hreadid=374651

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Program calling up Excel - Not running Macro

I suggest experimentally inserting the DoEvents line, say, after all of the
following, and see where it gets you. This is probably overkill:
i) MakeDirectory SavePath
ii) All Workbooks.Add, Save and Close code
iii) All Activate code
iv) The Cells.Copy line
v) The Cells.PasteSpecial xlPasteAll line

Regards,
Greg


"kraljb" wrote:


I have a program that calls up excel and inserts in numbers for
reporting purposes. I do not have access to the program that does this.
The program itself will print off the report once the information is in
it. I have changed the template to include a macro that runs on the
BeforePrint event.

Basically all I am doing is creating a new workbook, or editing an old
one depending on circumstances. However, while the macro runs fine when
I test it. Somehow, when the program calls up the file, it does not
error out (I have yet to put in error protection) but will skip over
some of the key steps (i.e. Workbooks.Add or Workbooks.Open( SavePath &
NewBookName) will not actually take place, but the code will act like
it did. It also skips over

Here is the actual code I only know the steps that is skipping that are
making it fail, I do not know if there are other steps that it is
missing.


Function ConsolidateDBR()
Dim SitePath As String
Dim SiteNum As String
Dim NewBookName As String
Dim MonthlyBook As Workbook
Dim SavePath As String
Dim CurrentBook As Workbook
Dim Counter As Long
Dim tmpSheet As String
Dim NewBook As Boolean
NewBook = False
SitePath = ActiveWorkbook.Path
Set CurrentBook = Workbooks(ActiveWorkbook.Name)
If Right(SitePath, 1) = "\" Then
SitePath = Left(SitePath, Len(SitePath) - 1)
End If
NewBookName = "DBR" & Format(Cells(3, 26).Value, "yyyy-mmm") &
".xls"
SiteNum = Mid(SitePath, 7, Len(SitePath) - 6)
SavePath = "C:\DBR-Report"
MakeDirectory SavePath
If Right(SavePath, 1) < "\" Then
SavePath = SavePath & "\"
End If
If Dir$(SavePath & NewBookName) = "" Then
Set MonthlyBook = Workbooks.Add
NewBook = True
MonthlyBook.SaveAs SavePath & NewBookName, xlNormal
Else
Set MonthlyBook = Workbooks.Open(SavePath & NewBookName, , False)
End If
CurrentBook.Activate
Cells.Copy
With MonthlyBook
.Activate
Counter = 1
While .Sheets.Count = Counter
If .Sheets(Counter).Name = SiteNum Then
tmpSheet = SiteNum
End If
Counter = Counter + 1
Wend
If tmpSheet = "" Then
If NewBook = False Then
.Sheets.Add
End If
.ActiveSheet.Name = SiteNum
End If
.Sheets(SiteNum).Select
End With
Cells.PasteSpecial xlPasteAll
MonthlyBook.Save
MonthlyBook.Close
End Function
Function MakeDirectory(Directory As String)
On Error GoTo Created:
MkDir (Directory)
Created:
End Function

Thank you in advance for your help

-John


--
kraljb
------------------------------------------------------------------------
kraljb's Profile: http://www.excelforum.com/member.php...fo&userid=9955
View this thread: http://www.excelforum.com/showthread...hreadid=374651


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
Pivot Refresh Error when calling Excel Macro from VB.NET program amdefacto Excel Discussion (Misc queries) 0 July 6th 09 10:06 AM
calling a C++ program from Excel 2000 and passing a result from C++ back to an excel spreadsheet ellis kurland Excel Discussion (Misc queries) 3 August 15th 05 04:10 PM
A program running on different Excel Versions Ian Stanborough Excel Programming 3 January 15th 05 05:06 AM
calling macro in excel from VB program Fung Excel Programming 1 July 21st 04 01:54 PM
Calling Access Program from Excel John Baker Excel Programming 1 April 24th 04 01:20 PM


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

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"