I have a workbook that uses function to check the Custom Defined Properties of the activeworkbook and compare it to the CDPs of another workbook. I open the 2nd workbook to retrieve the CDP and when I close I am prompted to save even though I have turned off alerts and tried both SaveChanges:=False, Saved = True.
Any idea what the issue is? The function (and the sub that call it) are below:
Function CheckSourceVersion(strSource, strVer)
'This function is used to check the Custom Document Property (CDP) of the link
Dim lngSourceCDP As Long
Dim lngCDP As Long
Dim strSourceVer As String
'Dim strVer As String
Dim bFound As Boolean
Dim strWb As String
'Open the link
Workbooks.Open strSource
strWb = Right(strSource, Len(strSource) - InStrRev(strSource, "\"))
'Count the number of CDPs in the link source & this workbook
lngSourceCDP = Workbooks(strWb).CustomDocumentProperties.Count
'lngCDP = ThisWorkbook.CustomDocumentProperties.Count
'Check that the source has at least 1 CDP
If lngSourceCDP > 0 Then
'Loop through the CDPs in the link source
For x = 1 To lngSourceCDP
'Check if the Version CDP exists
If LCase(Workbooks(strWb).CustomDocumentProperties(x).Name) = "version" Then
'If it exists, retrieve its value
strSourceVer = Workbooks(strWb).CustomDocumentProperties(x).Value
bFound = True
Exit For
End If
Next
'If the source has no CDPs
Else
bFound = False
End If
'Close the link source
Workbook(strWb).Close False
'If lngCDP > 0 Then
'
''Loop through this workbook's CDPs
'For x = 1 To lngCDP
' 'If Version exists, set the variable
' If ThisWorkbook.CustomDocumentProperties(x).Name = "Version" Then
' strVer = ThisWorkbook.CustomDocumentProperties(x).Value
' Exit For
' End If
'
'Next
'
'Else
' bFound = False
'End If
'If both workbooks have a version
If bFound = True Then
'If the versions match
If LCase(strVer) = LCase(strSourceVer) Then
CheckSourceVersion = "0," & strWb
'If the versions do not match
Else
CheckSourceVersion = "1," & strWb
End If
Else
'If the source had no version
CheckSourceVersion = "2," & strWb
End If
End Function
Display More
Option Explicit
Sub VerifyVersion()
'This sub is used to check the version between this workbook and
'the pack that this workbook is linked to
Dim strVer As String
Dim lngCDP As Long
Dim lngNumLinks As Variant
Dim lngResult As Long
Dim strSource As Variant
Dim strResult As Variant
Dim strWb As String
Dim x As Long
Dim lngNumXLSLinks As Long
Dim lngSource As Long
On Error GoTo ErrTrap
'Count the number of CDPs in this workbook
lngCDP = ThisWorkbook.CustomDocumentProperties.Count
'If at least 1 CDP exists
If lngCDP > 0 Then
'Loop through CDPs
For x = 1 To lngCDP
'If the version is found, set the variable
If LCase(ThisWorkbook.CustomDocumentProperties(x).Name) = "version" Then
strVer = ThisWorkbook.CustomDocumentProperties(x).Value
Exit For
End If
Next
'if there are no CDPs
Else
strVer = ""
End If
'If the version is found
If strVer <> "" Then
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Find the number of links in this workbook
lngNumLinks = UBound(ThisWorkbook.LinkSources(xlExcelLinks))
'Loop to find the number of xls links
For x = 1 To lngNumLinks
strSource = ThisWorkbook.LinkSources(xlExcelLinks)
If LCase(Right(strSource(x), 3)) = "xls" Then
lngNumXLSLinks = lngNumXLSLinks + 1
lngSource = x
End If
Next
'If more than 1 xls link is found
'Show the form for the user to select the link to check
If lngNumXLSLinks > 1 Then
frmVersion.Show
'Make sure the user did not click cancel on the form
If frmVersion.cbFile.Value = "" Then
'Allow the user to exit
If MsgBox("You must select a file!" & vbCr & vbCr & "Do you want to continue?" & vbCr & vbCr & _
"Click Yes to Continue, No to Exit", vbQuestion + vbYesNo, "Continue?") <> vbYes Then
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Exit Sub
'If they do not exit, show the link form again
Else
frmVersion.Show
End If
End If
'Check the version by calling the function passing the link and this workbook version
strResult = CheckSourceVersion(frmVersion.cbFile.Value, strVer)
Unload frmVersion
Else
'If only 1 link exists, pass it to the function
strSource = ThisWorkbook.LinkSources(xlExcelLinks)
strSource = strSource(lngSource)
strResult = CheckSourceVersion(strSource, strVer)
End If
'If the version does not exist in this workbook, exit the macro
Else
MsgBox "The version of this workbook cannot be determined." & vbCr & vbCr & _
"Please contact someone for assistance.", vbInformation + vbOKOnly, "Version Not Found!"
ThisWorkbook.Sheets("Control Tab").range("B6").Value = False
Exit Sub
End If
'Put the results of the function into an array
strResult = Split(strResult, ",")
'Used to determine the message
lngResult = strResult(0)
strWb = strResult(1)
'Based on the function return value
Select Case lngResult
'Versions match
Case 0
MsgBox "The versions match!", vbInformation + vbOKOnly, "Versions Match"
With ThisWorkbook.Sheets("Control Tab").Shapes("Step6")
.Fill.Solid
.Fill.ForeColor.SchemeColor = 11
End With
'Versions do not match
Case 1
MsgBox "The current version for HFM is: '" & strVer & "'" & vbCr & vbCr & _
"This does not match the version in the link:" & vbCr & _
" -" & strWb & vbCr & vbCr & _
"Please update your links to the correct version!", vbExclamation + vbOKOnly, _
"Versions Do NOT Match!"
With ThisWorkbook.Sheets("Control Tab").Shapes("Step5")
.Fill.Solid
.Fill.ForeColor.SchemeColor = 9
End With
With ThisWorkbook.Sheets("Control Tab").Shapes("Step6")
.Fill.Solid
.Fill.ForeColor.SchemeColor = 10
End With
ThisWorkbook.Sheets("Control Tab").range("B5").Value = False
ThisWorkbook.Sheets("Control Tab").range("B6").Value = False
'Source link does not have a version
Case 2
MsgBox "The source file does not have a version!" & vbCr & vbCr & _
"Please update your links to the correct version!", _
vbExclamation + vbOKOnly, "Missing Version"
With ThisWorkbook.Sheets("Control Tab").Shapes("Step5")
.Fill.Solid
.Fill.ForeColor.SchemeColor = 9
End With
With ThisWorkbook.Sheets("Control Tab").Shapes("Step6")
.Fill.Solid
.Fill.ForeColor.SchemeColor = 10
End With
ThisWorkbook.Sheets("Control Tab").range("B5").Value = False
ThisWorkbook.Sheets("Control Tab").range("B6").Value = False
' Case 3
' MsgBox "This file does not have a version!" & vbCr & vbCr & _
' "Please ensure that you are using the current version.", _
' vbExclamation + vbOKOnly, "Missing Version"
End Select
ErrTrap:
If Err.Number <> 0 Then
MsgBox "The following error was encounter:" & vbCr & _
" Error " & Err.Number & " - " & Err.Description & vbCr & vbCr & _
"The version check did not complete!", vbExclamation + vbOKOnly, "Error"
End If
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Display More