Gord Dibben said:
Which version of Excel are you using?
I am using excel 2007.
What do you mean by "open a macro"?
There is a macro on my spreadsheet which links to another workbook. When I
click on the maco called "Open Target workbook" I get the option to select
the file where my data is stored for the macro. The problem is I can't
filter the file extensions for .xlsx. I only have the option to open a .xls
format spreadsheet.
Is this the code?
Sub fsCheckData()
fsInitializeVariables
' Check the Mapping and Desc fields to ensure we have the same rows in
both sheets
currRow = 0
For targetRow = targetMappingColumnFirstRow To targetMappingColumnLastRow
If Not
(Workbooks(targetWorkbook).Worksheets(targetWorksheet).Rows(targetRow).Hidden) Then
If Not (Cells(fsStartRow + currRow, 1).Value = "") And _
(Not (Cells(fsStartRow + currRow, 1).Value =
Workbooks(targetWorkbook).Sheets(targetWorksheet).Cells(targetRow,
targetMappingColumn).Value) Or _
Not (Cells(fsStartRow + currRow, 2).Value =
Workbooks(targetWorkbook).Sheets(targetWorksheet).Cells(targetRow,
targetDescField1).Value) Or _
Not (Cells(fsStartRow + currRow, 3).Value =
Workbooks(targetWorkbook).Sheets(targetWorksheet).Cells(targetRow,
targetDescField2).Value)) Then
MsgBox ("Data Mismatch Error for Row " + Trim(Str(fsStartRow
+ currRow)) + Chr(13) + "Rows data in first three columns of this spreadsheet
must match those in target workbook.")
Exit Sub
End If
currRow = currRow + 1
End If
Next
' Now, re-copy the formula for the URL delimiter
' Reason: there have been bugs when adding / removing cells (ie: when
creating group / folder IDs)
' Easiest fix is to just re-copy as the last step in the process (when
the check / set data button is clicked)
' numberOfRows is the number of rows of client data in the
IntraLinksFileSplit worksheet
numberOfRows = targetMappingColumnLastRow - targetMappingColumnFirstRow
Range("P" + Trim(Str(fsTemplateRow)) + "
" + Trim(Str(fsStartRow +
numberOfRows))).Select
Selection.FillDown
Range("P" + Trim(Str(fsStartRow)) + "
" + Trim(Str(fsStartRow +
numberOfRows))).Select
Selection.Interior.ColorIndex = xlNone
targetNumRows = currRow - 1
'loop through every row and check for data
dataCheckList = ""
For currRow = fsStartRow To (fsStartRow + targetNumRows)
If Not (Cells(currRow, 1) = "") Then
If Not ((Cells(currRow, 5).Value = True) Or (Cells(currRow,
5).Value = False)) Then
dataCheckList = dataCheckList + "Cell E" +
Trim(Str(currRow)) + " must be True or False!" + Chr(13)
End If
If (Worksheets(fsSheetName).Cells(currRow, 5).Value = True) Then
'Upload=True
If (Worksheets(fsSheetName).Cells(currRow, 4).Value = "")
Then 'filename is empty
dataCheckList = dataCheckList + "Cell D" +
Trim(Str(currRow)) + " is empty!" + Chr(13)
End If
If (Worksheets(fsSheetName).Cells(currRow, 6).Value = "")
Then 'no workspace ID specified
dataCheckList = dataCheckList + "Cell F" +
Trim(Str(currRow)) + " is empty!" + Chr(13)
End If
If CStr(Worksheets(fsSheetName).Cells(currRow, 7).Value) =
"Error 2042" Then 'folderID lookup failed
dataCheckList = dataCheckList + "Cell G" +
Trim(Str(currRow)) + " is empty!" + Chr(13)
End If
If CStr(Worksheets(fsSheetName).Cells(currRow, 9).Value) =
"Error 2042" Then 'group ID
dataCheckList = dataCheckList + "Cell I" +
Trim(Str(currRow)) + " is empty!" + Chr(13)
End If
If Not ((Worksheets(fsSheetName).Cells(currRow, 11).Value =
"SEE") Or (Worksheets(fsSheetName).Cells(currRow, 11).Value = "CONTROL") Or
(Worksheets(fsSheetName).Cells(currRow, 11).Value = "S") Or
(Worksheets(fsSheetName).Cells(currRow, 11).Value = "C")) Then 'permission
type
dataCheckList = dataCheckList + "Cell K" +
Trim(Str(currRow)) + " must be SEE or CONTROL!" + Chr(13) +
Worksheets(fsSheetName).Cells(currRow, 11).Value
End If
If (Worksheets(fsSheetName).Cells(currRow, 12).Value = "")
Then 'pub title
dataCheckList = dataCheckList + "Cell L" +
Trim(Str(currRow)) + " is empty!" + Chr(13)
End If
If (Worksheets(fsSheetName).Cells(currRow, 13).Value = "")
Then 'effective date
dataCheckList = dataCheckList + "Cell M" +
Trim(Str(currRow)) + " is empty!" + Chr(13)
End If
If Not ((Worksheets(fsSheetName).Cells(currRow, 14).Value =
"DRMOn") Or (Worksheets(fsSheetName).Cells(currRow, 14).Value = "DRMOff") Or
(Worksheets(fsSheetName).Cells(currRow, 14).Value = "D2")) Then 'permission
type
dataCheckList = dataCheckList + "Cell N" +
Trim(Str(currRow)) + " must be DRMOn of DRMOff!" + Chr(13)
End If
If Not ((Worksheets(fsSheetName).Cells(currRow, 15).Value =
"SAT") Or (Worksheets(fsSheetName).Cells(currRow, 15).Value = "SAF") Or
(Worksheets(fsSheetName).Cells(currRow, 15).Value = "SAD")) Then 'send alert
type
dataCheckList = dataCheckList + "Cell O" +
Trim(Str(currRow)) + " must be SendAlertTrue or SendAlertFalse!" + Chr(13)
End If
If CStr(Worksheets(fsSheetName).Cells(currRow, 16).Value) =
"Error 2042" Then 'delimiter is empty
dataCheckList = dataCheckList + "Cell P" +
Trim(Str(currRow)) + " is empty!" + Chr(13)
End If
End If
End If
Next
'Make a call here to the function to check length of PDF names
dataCheckList = dataCheckList + CheckLengthOfPDFNames()
If (dataCheckList = "") Then
' Set the target column data
currRow = 0
For targetRow = targetMappingColumnFirstRow To
targetMappingColumnLastRow
If Not
(Workbooks(targetWorkbook).Worksheets(targetWorksheet).Rows(targetRow).Hidden) Then
If Not (Cells(fsStartRow + currRow, 1) = "") Then
' the following change actually writes the data to the
target workbook (rather than just referencing it)
ILURLReferenceCellString = "URL:" &
Workbooks(fsFileName).Worksheets(fsSheetName).Cells((fsStartRow + currRow),
16).Value
Workbooks(targetWorkbook).Sheets(targetWorksheet).Cells(targetRow,
targetURLColumn) = ILURLReferenceCellString
End If
currRow = currRow + 1
End If
Next
MsgBox ("Done Checking Data and Setting URL Data in Target Workbook")
Else
MsgBox (dataCheckList)
MsgBox ("Target URL data not set due to errors!")
End If
Cells(1, 1).Select
End Sub
'
' Private Helper Functions
'
Private Function fsWorkbookExists(ByVal workbookName As String) As Boolean
' Checks if the workbook exists
For Each w In Workbooks
If (w.Name = workbookName) Then
fsWorkbookExists = True
Exit Function
End If
Next
fsWorkbookExists = False
End Function
Private Function fsWorksheetExists(ByVal workbookName As String, ByVal
sheetName As String) As Boolean
' Checks if the worksheet exists in the workbook
For Each s In Workbooks(workbookName).Sheets
If (s.Name = sheetName) Then
fsWorksheetExists = True
Exit Function
End If
Next
fsWorksheetExists = False
End Function
Public Function CharacterCleanPDFName(text As String, allowSpaces As
Boolean) As String
'
' This function cleans a dirty string...changes bad characters to harmless
ones.
'
Dim tempText
tempText = text
tempText = Replace(tempText, "/", "_")
tempText = Replace(tempText, "\", "_")
tempText = Replace(tempText, "|", "_")
tempText = Replace(tempText, ":", "_")
tempText = Replace(tempText, "*", "_")
tempText = Replace(tempText, "?", "_")
tempText = Replace(tempText, """", "_")
tempText = Replace(tempText, "<", "_")
tempText = Replace(tempText, ">", "_")
tempText = Replace(tempText, "!", "_")
tempText = Replace(tempText, "@", "_")
tempText = Replace(tempText, "#", "_")
tempText = Replace(tempText, "$", "_")
tempText = Replace(tempText, "%", "_")
tempText = Replace(tempText, "^", "_")
tempText = Replace(tempText, "&", "_")
tempText = Replace(tempText, "*", "_")
tempText = Replace(tempText, "=", "_")
tempText = Replace(tempText, "~", "_")
tempText = Replace(tempText, ",", "_")
' remove apostrophes -> currently in production (4.0.25.18) there is a
bug that
' does not allow PDFs with apostrophes to be rendered in the browser
tempText = Replace(tempText, "'", "") 'just remove apostrophe; don't
swap in underscore
If Not (allowSpaces) Then
tempText = Replace(tempText, " ", "_")
End If
CharacterCleanPDFName = tempText
End Function
Public Function CharacterCleanPublication(text As String, allowSpaces As
Boolean) As String
'
' This function cleans a dirty string...changes bad characters to harmless
ones.
'
Dim tempText
tempText = text
tempText = Replace(tempText, "/", "_")
tempText = Replace(tempText, "\", "_")
tempText = Replace(tempText, "|", "_")
tempText = Replace(tempText, ":", "_")
tempText = Replace(tempText, "*", "_")
tempText = Replace(tempText, "?", "_")
tempText = Replace(tempText, """", "_")
tempText = Replace(tempText, "<", "_")
tempText = Replace(tempText, ">", "_")
tempText = Replace(tempText, "!", "_")
tempText = Replace(tempText, "@", "_")
tempText = Replace(tempText, "#", "_")
tempText = Replace(tempText, "$", "_")
tempText = Replace(tempText, "%", "_")
tempText = Replace(tempText, "^", "_")
tempText = Replace(tempText, "&", "_")
tempText = Replace(tempText, "*", "_")
tempText = Replace(tempText, "=", "_")
tempText = Replace(tempText, "~", "_")
tempText = Replace(tempText, ",", "_")
If Not (allowSpaces) Then
tempText = Replace(tempText, " ", "_")
End If
CharacterCleanPublication = tempText
End Function
Private Function CheckLengthOfPDFNames() As String
' Checks to ensure that PDF name is less than 50 characters
' This is a bug with ARTS Split Pro (PDF Splitter)
' Remove this function when they have fixed this
' This function takes no arguments. It is only called from another sub /
function
' that has already set global variables. Uses:
' targetMappingColumnFirstRow
' targetMappingColumnLastRow
'numberOfRows holds the number of rows in the data set
numberOfRows = targetMappingColumnLastRow - targetMappingColumnFirstRow
+ 1
' lastRow holds the real value of last row of data to be operated on
lastRow = fsStartRow + numberOfRows - 1
' currentRow increments from the 1st data row to the last data row
For currentRow = fsStartRow To lastRow
If Not (Cells(currentRow, 1) = "") Then 'TO DO : do i need this
check ?
' check the length of the current filename
If (Len(Cells(currentRow, 4).Value) > 50) Then
longFileNames = longFileNames + "Row " +
Trim(Str(currentRow)) + ": " + Cells(currentRow, 4) + Chr(13)
End If
End If
Next
' as necessary, construct return string
If (longFileNames = "") Then
CheckLengthOfPDFNames = longFileNames
Exit Function
End If
CheckLengthOfPDFNames = Chr(13) + "Long PDF filenames (max is 50 chars
excluding '.pdf'): " + Chr(13) + longFileNames
End Function