B
BrianG
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
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