LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default macro works in .xlt but not .xls

I've created a purchase order template (purchord.xlt) whose number
comes from a sheet in a seperate workbook (newponum.xls). The sole
purpose of this sheet is to increment the number. When I test the
macro while the template is open it works fine but when I start Excel
with the template, the macro fails. The problem is that the
newponum.xls is being opened as newponum2. Here's the portion of my
code that creates the purchase order number and prepares for data
entry (don't laugh, I admit to not being a VB programmer):

Dim wpath As String ' wPath = Working Path
Dim tpath As String ' tPath = Temporary file Path
Dim tFilename As String ' tFilename = Temporary Filename
wpath = "c:\temp\po project" 'Set working path
tpath = Environ("temp") 'Set temp path
If tpath = "" Then
tpath = Environ("tmp")
End If

Dim TB As Worksheet
PO = MsgBox("Start a new Purchase Order?", vbYesNo, "New Purchase
Order?")
If PO = vbNo Then GoTo C 'Close worksheet and exit on cancel

tFilename = Range("AB1") & "_tmp"
ChDrive tpath 'Change drive to location of temp folder
ChDir tpath 'Change directory to path of temp folder

ThisWorkbook.SaveAs filename:=tFilename, FileFormat:=xlNormal

ChDir wpath 'Change directory to working path

Sheets(1).ScrollArea = "b1:ac135" 'Sets the scroll area

Set TB = ThisWorkbook.Worksheets(1)

On Error GoTo E
Application.ScreenUpdating = False
Workbooks.Open "nextponum.xls"
Range("A1") = Range("A1") + 1
TB.Range("AB1") = "C" & Range("A1")
ActiveWorkbook.Close SaveChanges:=True
ThisWorkbook.Activate
TB.Select
TB.Range("AB1") = "C" & NewNum
Application.ScreenUpdating = True
Exit Sub

E:
MsgBox "Excel could not assign a new number to this purchase
order." & Chr(13) & _
"The NEXTPONUM.XLS file could not be found." & Chr(13) & _
"Contact your network admin for assistance.", , "Error - Procedure
Failed!"
C:
ThisWorkbook.Close SaveChanges:=False

End Sub
 
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
Clean Macro that WORKS... DR Excel Worksheet Functions 3 October 8th 09 09:52 PM
macro that works one time every day Spiros Excel Discussion (Misc queries) 2 September 19th 08 12:00 PM
Macro works Macro does not work Wanna Learn Excel Discussion (Misc queries) 4 March 24th 08 12:51 PM
Macro do works in excel... driller Excel Worksheet Functions 7 July 12th 07 02:56 PM
Email Macro only sometime works? PaulW Excel Discussion (Misc queries) 0 August 15th 06 10:22 AM


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