Is there a way to reset all variables to null with one command. What happens is...
When I run this macro the first time, all the inputs are blank (as expected). When I run it a second time, all the inputs are filled with the values from the initial run (not as expected).
Code:
Option Explicit
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Function GetValue(ByVal sValue As String) As Integer
If sValue = "" Then
GetValue = 0
Else
GetValue = Val(sValue)
End If
End Function
Private Sub buttonBrowse_Click()
ShowOpenFile
End Sub
Private Sub buttonCancel_Click()
Unload Me
End Sub
Private Sub buttonOK_Click()
If ValidateParams Then
CreateVinylStreetBanner.Hide
CreatePageLayout
End If
End Sub
Private Function ValidateParams() As Boolean
ValidateParams = True
If (IsNumeric(boxWidth.Text) = False) Then GoTo ErrWidth
If (IsNumeric(boxHeight.Text) = False) Then GoTo ErrHeight
If (IsNumeric(boxSleeve.Text) = False) Then GoTo ErrSleeve
Exit Function
ErrWidth:
MsgBox "Spacing not numeric : " & boxWidth.Text
boxWidth.SetFocus
ValidateParams = False
Exit Function
ErrHeight:
MsgBox "Spacing not numeric : " & boxHeight.Text
boxHeight.SetFocus
ValidateParams = False
Exit Function
ErrSleeve:
MsgBox "Spacing not numeric : " & boxSleeve.Text
boxSleeve.SetFocus
ValidateParams = False
Exit Function
End Function
Public Sub ShowOpenFile()
Dim OFName As OPENFILENAME
Dim sPath As String
Dim GetBackEnd As String
Dim BrowseOpenFile As String
Dim n As String
OFName.lStructSize = Len(OFName)
OFName.hwndOwner = 0&
OFName.hInstance = 0&
OFName.lpstrFilter = "Image Files" + Chr$(0) + "*.ai;*.cdr;*.eps;*.pdf;*.cmx"
OFName.lpstrFile = Space$(254)
OFName.nMaxFile = 255
OFName.lpstrFileTitle = Space$(254)
OFName.nMaxFileTitle = 255
sPath = GetBackEnd
If sPath = vbNullString Then
OFName.lpstrInitialDir = "D:\By Customer\"
Else
sPath = Left(sPath, InStrRev(sPath, "\") - 1)
If Len(Dir(sPath, vbDirectory)) > 0 Then
OFName.lpstrInitialDir = sPath
Else
OFName.lpstrInitialDir = "D:\By Customer\"
End If
End If
OFName.lpstrTitle = "Select an image File (*.ai), (*.cdr), (*.cmx), (*.eps), (*.pdf)"
OFName.flags = 0
If GetOpenFileName(OFName) Then
BrowseOpenFile = OFName.lpstrFile
Else
BrowseOpenFile = vbNullString
MsgBox "No file Selected."
End If
boxFile.Text = BrowseOpenFile
End Sub
Public Sub CreatePageLayout()
Dim doc As Document
Dim BrowseOpenFile As String
Dim OFName As OPENFILENAME
Dim docH As Long
Dim docW As Long
Dim dw As Integer
Dim dh As Integer
Dim sl As Integer
Dim sewn As Integer
Dim p As Page
dw = GetValue(boxWidth.Value)
dh = GetValue(boxHeight.Value)
sl = GetValue(boxSleeve.Value)
docH = dh + dh + sl
docW = dw + 1
Set doc = CreateDocument()
doc.Unit = cdrInch
ActiveDocument.Pages(0).SetSize docW, (docH + 0.5)
With ActivePage
.Orientation = cdrPortrait
.SizeWidth = docW
.SizeHeight = (docH + 0.5)
.PrintExportBackground = False
.Bleed = 0#
.Background = cdrPageBackgroundNone
End With
With ActiveLayer
.CreateGuide 0, 0, 0, docH
.CreateGuide docW, 0, docW, docH
.CreateGuide (docW - 0.5), 0, (docW - 0.5), docH
.CreateGuide 0.5, 0, 0.5, docH
.CreateGuide 0, 0, docW, 0
.CreateGuide 0, sl, docW, sl
.CreateGuide 0, (dh - sl), docW, (dh - sl)
.CreateGuide 0, dh, docW, dh
.CreateGuide 0, (dh + sl), docW, (dh + sl)
.CreateGuide 0, (dh * 2), docW, (dh * 2)
.CreateGuide 0, (dh * 2 + (sl + 0.5)), docW, (dh * 2 + (sl + 0.5))
End With
If boxFile.Text <> "" Then
Dim s5 As Shape, s6 As Shape
Dim x As Double, y As Double, q As Double, z As Double
Dim nsy As Double
ActiveLayer.Import boxFile.Text, cdrAutoSense
Set s5 = ActiveSelection
s5.Move 0#, 0#
ActiveDocument.ReferencePoint = cdrCenter
s5.GetPosition x, y
s5.PositionX = (docW / 2)
s5.PositionY = (s5.SizeHeight / 2)
Set s6 = s5.Clone(0, dh)
s6.Rotate 180
End If
Dim ext As Layer
Dim sq As Shape
Set ext = ActivePage.CreateLayer("Extras")
ActivePage.Layers("Extras").Activate
ActiveLayer.CreateRectangle 0, 0, docW, sl
ActiveSelection.Fill.UniformColor.CMYKAssign 0, 0, 0, 0
ActiveLayer.CreateCurveSegment 0, (dh - sl), docW, (dh - sl)
ActiveSelection.Outline.Color.CMYKAssign 0, 0, 0, 0
ActiveSelection.Outline.Width = 0.028
ActiveLayer.CreateCurveSegment 0, dh, 2, dh
ActiveSelection.Outline.Color.CMYKAssign 0, 0, 0, 0
ActiveSelection.Outline.Width = 0.028
ActiveLayer.CreateCurveSegment (docW - 2), dh, docW, dh
ActiveSelection.Outline.Color.CMYKAssign 0, 0, 0, 0
ActiveSelection.Outline.Width = 0.028
ActiveLayer.CreateCurveSegment 0, (dh * 2), 2, (dh * 2)
ActiveSelection.Outline.Color.CMYKAssign 0, 0, 0, 0
ActiveSelection.Outline.Width = 0.028
ActiveLayer.CreateCurveSegment (docW - 2), (dh * 2), docW, (dh * 2)
ActiveSelection.Outline.Color.CMYKAssign 0, 0, 0, 0
ActiveSelection.Outline.Width = 0.028
End Sub