Ok I see that the property is declared inside an IF statement and then tried to be used outside of that. This is not posible to do insise of an IF or loop so when this is the case you will need to set something of a declared variable or public property decalared outside of this to make it available through the process. I have included that I think will work for you below.
Public Sub Main()
'Check if publish rule intentional
Dim SymbolName As String = Nothing ' we are going to declare this and set it to nothing early in the game and use it later
question = MessageBox.Show("Ready to commence publishing?", "Confirm Publish", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If question = vbNo Then
Return
Else
End If
'Define pdf and dwg file locations
strPublishedFolder = ThisDoc.Path & "\Published"
'Make output folders if they don't exist
strPdfFolder = strPublishedFolder & "\PDF"
If Dir(strPdfFolder, vbDirectory) = "" Then MkDir(strPdfFolder)
strDwgFolder = strPublishedFolder & "\DWG"
If Dir(strDwgFolder, vbDirectory) = "" Then MkDir(strDwgFolder)
'Title block selection from external file
ThisDrawing.ResourceFileName = "D:\Local Server\Data\Autodesk Customization\Templates\IV2014TitleBlocks.idw"
ThisDrawing.KeepExtraResources = False
Dim strSelectedTB As String = "Result"
Dim strTitleBlock As New ArrayList
strTitleBlock.Add("EMAL")
strTitleBlock.Add("EmalP2")
strTitleBlock.Add("KMP")
strSelectedTB = InputListBox("Select a Title Block", strTitleBlock, strSelectedTB, "Title Block Selection", "Available Title Blocks")
'Query stamp insertion requirement
question = MessageBox.Show("Do you want to insert a stamp?", "Stamp Requirement", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If question = vbYes Then
Dim strSelectedStamp As String = "Result2"
Dim strStampList As New ArrayList
strStampRequired = True
Dim strDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim SourceFile As String = "D:\Local Server\Data\Autodesk Customization\Templates\IV2014Stamps.idw"
Dim strSourceIDW As DrawingDocument
strSourceIDW = ThisApplication.Documents.Open(SourceFile, False)
Dim symbolDef As SketchedSymbolDefinition
For Each symbolDef In strSourceIDW.SketchedSymbolDefinitions
strStampList.Add(symbolDef.Name)
Next
strSelectedStamp = InputListBox("Please select a stamp.", strStampList, strSelectedStamp, "Stamp Selection", "Available Stamps")
For Each symbolDef In strSourceIDW.SketchedSymbolDefinitions
If (StrComp(symbolDef.Name, strSelectedStamp, vbTextCompare) = 0) Then
CopyFrom = symbolDef.CopyTo(strDrawDoc, True)
SymbolName = symbolDef.Name
End If
Next
strSourceIDW.Close()
MessageBox.Show("You have selected " & strSelectedStamp, "Stamp Selection Feedback")
Else
strStampRequired = False
End If
'Step through each sheet in the IDW
Dim strSheets As Sheets
strSheets = ThisDoc.Document.sheets
Dim strSheet As Sheet
For Each strSheet In strSheets
strSheet.activate()
'Truncate the sheet instance from the sheet name, keeping the digits before the colon
SheetName = ActiveSheet.Name
ColonIndex = SheetName.LastindexOf(":")
strCurrentSeqNum = SheetName.substring(0, ColonIndex)
'Access the Titleblock Data spreadsheet and select the row corresponding to the active drawing sheet
i = GoExcel.FindRow("TBData.xlsx", "Sheet1", "SEQNO", "=", strCurrentSeqNum)
'Get the cell values for the designated row
strArea = GoExcel.CurrentRowValue("AREA")
'<snipped for length>
strDocType = GoExcel.CurrentRowValue("DOC/TYPE")
'Populate the Custom iProperties with the TBData values
iProperties.Value("Custom", "AREA") = strArea
'<snipped for length>
iProperties.Value("Custom", "DOC/TYPE") = strDocType
'Insert the border on the active sheet
ActiveSheet.Border = "HEL"
'Insert the titleblock on the active sheet
ActiveSheet.TitleBlock = strSelectedTB
'Insert stamp if required
If strStampRequired = True And Not SymbolName Is Nothing Then ' we will make sure it is wanted and also check that the property declared
' at the top of this sub was set to something so we dont pass an empty string
InsertSymbol(SymbolName)
'Dim strDrawDoc As DrawingDocument = ThisDrawing.Document
'Dim strSketchedSymbolDef As SketchedSymbolDefinition = strDrawDoc.SketchedSymbolDefinitions.Item(strSelectedStamp)
'Dim strTransGeom = ThisApplication.TransientGeometry
'Dim strInsertionPoint As Point2d = strTransGeom.CreatePoint2d(5.5,13)
'Dim strSketchedSymbol As SketchedSymbol = strSheet.SketchedSymbols.Add(strSketchedSymbolDef,strInsertionPoint,0,0.75,Nothing)
Else
End If
MessageBox.Show("All properties have been applied to " & strCurrentSeqNum, "Title Block Data Status")
'---------------Export the sheet to pdf------------------------
'Assign path and file name
strFullFileName = strPdfFolder & "\" & strFileNum2 & ".pdf"
strPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
strDocument = ThisApplication.ActiveDocument
strContext = ThisApplication.TransientObjects.CreateTranslationContext
strContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
strOptions = ThisApplication.TransientObjects.CreateNameValueMap
strDataMedium = ThisApplication.TransientObjects.CreateDataMedium
If strPDFAddIn.HasSaveCopyAsOptions(strDataMedium, strContext, strOptions) Then
strOptions.Value("All_Color_AS_Black") = 0
strOptions.Value("Remove_Line_Weights") = 0
strOptions.Value("Vector_Resolution") = 400
strOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet
End If
'Set the PDF target file name
strDataMedium.FileName = strFullFileName
'Publish document as PDF
strPDFAddIn.SaveCopyAs(strDocument, strContext, strOptions, strDataMedium)
'----------- export the sheet to dwg -------------------
'Assign path and file name
strFullFileName = strDwgFolder & "\" & strFileNum2 & ".dwg"
' Get the DWG translator Add-In.
strDWGAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
strContext = ThisApplication.TransientObjects.CreateTranslationContext
strContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
strOptions = ThisApplication.TransientObjects.CreateNameValueMap
strDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If strDWGAddIn.HasSaveCopyAsOptions(strDocument, strContext, strOptions) Then
' DWG version.
' 23 = ACAD 2000
' 25 = ACAD 2004
' 27 = ACAD 2007
' 29 = ACAD 2010
strOptions.Value("DwgVersion") = 27
Dim strIniFile As String
strIniFile = "D:\Local Server\Data\Heaslip Autodesk Customization\Templates\DWGSubmittalConfig.ini"
' Create the name-value that specifies the ini file to use.
strOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'Set the DWG target file name
strDataMedium.FileName = strFullFileName
'Publish the active sheet as DWG 2007
strDWGAddIn.SaveCopyAs(strDocument, strContext, strOptions, strDataMedium)
'Delete the titleblock, border, and stamp from the current sheet before continuing to the next sheet
strSheet.TitleBlock.Delete()
strSheet.Border.Delete()
'MessageBox.Show("Sheet " & strCurrentSeqNum & " has successfully been exported", "Sheet Publish Status")
Next
MessageBox.Show("Publishing Completed", "")
End Sub
Private Sub InsertSymbol(ByVal SymbName As String)
Dim strDrawDoc As DrawingDocument = ThisDrawing.Document
Dim strSheet As Sheet = strDrawDoc.ActiveSheet
Dim strSketchedSymbolDef As SketchedSymbolDefinition = strDrawDoc.SketchedSymbolDefinitions.Item(SymbName)
Dim strTransGeom = ThisApplication.TransientGeometry
Dim strInsertionPoint As Point2d = strTransGeom.CreatePoint2d(5.5, 13)
Dim strSketchedSymbol As SketchedSymbol = strSheet.SketchedSymbols.Add(strSketchedSymbolDef, strInsertionPoint, 0, 0.75, Nothing)
End Sub