Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Microsoft macros created in OS 9 dont work in OS X

Dec 10, 2004 3:48AM PST

Hi I'm using a Microsoft document on a Mac that has macros
it works fine in OS 9 environment but does not work in OS X.

I'm wondering if it's the syntx that has changed and it can't understand it in OS X since OS X is unix based.

Here is the macro code, what happens if you try to run the macro it
crashes word.

Ohh I just tested in Windows 2000 and it works fine there.

----AwardUpdater Macro - modMain (Code) ----------------

Option Explicit

Global CHECKMARK_COUNT_COLUMN As String
Global BGRP_MESSAGES_COLUMN As String
Global FUND_MESSAGES_COLUMN As String

Global CHECKMARK_HEADER As String
Global CHECKMARK_TOKEN As String
Global MERGE_FOLDER As String
Global MERGE_LIST As Variant
Global DIR_SEPERATOR As String

Sub RunMergeUpdater()
Call SetGlobals
Call UpdateMergeList
frmMain.Show
End Sub


Sub SetGlobals()
Select Case ThisDocument.Application.System.OperatingSystem
Case Is = "Macintosh"
DIR_SEPERATOR = ":"
Case Else
DIR_SEPERATOR = "\"
End Select

CHECKMARK_COUNT_COLUMN = "AWARD_DESC"
BGRP_MESSAGES_COLUMN = "BGRP_MESSAGES"
FUND_MESSAGES_COLUMN = "FUND_MESSAGES"

CHECKMARK_HEADER = "CHECKMARK_COL"
CHECKMARK_TOKEN = "[ ]"
MERGE_FOLDER = ThisDocument.Path & DIR_SEPERATOR & "merge" & DIR_SEPERATOR
MERGE_LIST = Array()
End Sub

Function SplitLine(ByVal LineData As String, ByVal Delimiter As String) As Variant
Dim Temp As String
Dim TempArray As Variant

LineData = Delimiter & LineData
TempArray = Array()
Do While Trim(LineData) <> ""
If InStr(Len(Delimiter) + 1, LineData, Delimiter) < 1 Then
Temp = Right(LineData, Len(LineData) - Len(Delimiter))
LineData = ""
Else
Temp = Mid(LineData, 1, InStr(Len(Delimiter) + 1, LineData, Delimiter) - 1) 'Len(Delimiter))
Temp = Right(Temp, Len(Temp) - Len(Delimiter))
LineData = Mid(LineData, InStr(Len(Delimiter) + 1, LineData, Delimiter))
End If
ReDim Preserve TempArray(UBound(TempArray) + 1)
TempArray(UBound(TempArray)) = Temp
Loop
SplitLine = TempArray
End Function

Function JoinArray(ByVal TempArray As Variant, ByVal Delimiter As String) As String
Dim Index As Variant
If UBound(TempArray) < 0 Then
JoinArray = ""
Exit Function
End If
For Each Index In TempArray
JoinArray = JoinArray & Index & Delimiter
Next Index
JoinArray = Left(JoinArray, Len(JoinArray) - Len(Delimiter))
End Function

Function InStrReverse(ByVal StringCheck As String, ByVal StringMatch As String, Optional ByVal Start As Integer = -1) As Integer
If Len(StringCheck) = 0 Then
InStrReverse = 0
Exit Function
End If
If IsNull(StringCheck) Then
InStrReverse = Null
Exit Function
End If
If Len(StringMatch) = 0 Then
InStrReverse = Start
Exit Function
End If
If InStr(1, StringCheck, StringMatch) < 1 Then
InStrReverse = 0
Exit Function
End If
If Start > Len(StringMatch) Then
InStrReverse = 0
Exit Function
End If

Dim Index As Variant
Dim Temp As Variant
Dim CharData As String
Dim ReverseCheck As String
Dim ReverseMatch As String

Temp = StringCheck
For Index = 0 To Len(Temp)
If Temp = "" Then Exit For
CharData = Mid(Temp, 1, 1)
Temp = Right(Temp, Len(Temp) - 1)
ReverseCheck = CharData & ReverseCheck
Next Index

Temp = StringMatch
For Index = 0 To Len(Temp)
If Temp = "" Then Exit For
CharData = Mid(Temp, 1, 1)
Temp = Right(Temp, Len(Temp) - 1)
ReverseMatch = CharData & ReverseMatch
Next Index

InStrReverse = Len(ReverseCheck) - InStr(1, ReverseCheck, ReverseMatch)
End Function

Function StrReplace(ByVal StartString As String, ByVal SearchString As String, ByVal ReplaceString As String) As String
If IsNull(StartString) = True Then
StrReplace = Null
Exit Function
End If
If IsNull(SearchString) = True Then
StrReplace = Null
Exit Function
End If
If Len(StartString) = 0 Then
StrReplace = StartString
Exit Function
End If
If Len(SearchString) = 0 Then
StrReplace = StartString
Exit Function
End If

Dim SearchLoc As Integer
SearchLoc = 1
While InStr(SearchLoc, StartString, SearchString) <> 0
Dim LeftPart As String
Dim RightPart As String
Dim Location As Integer

'replace string with what we need to
Location = InStr(1, StartString, SearchString)
LeftPart = Left(StartString, Location - Len(SearchString))
RightPart = Right(StartString, Len(StartString) - Location)

StartString = LeftPart & ReplaceString & RightPart
SearchLoc = Len(LeftPart) + Len(ReplaceString)
Wend
StrReplace = StartString
End Function

Sub UpdateMergeList()
Dim File As String
Dim Index As Object
Dim HeaderList As Variant

File = Dir(MERGE_FOLDER)
frmMain.lstMergeFiles.Clear
While File <> ""
HeaderList = GetHeader(MERGE_FOLDER & File)
If HeaderUpdated(HeaderList) = True Then File = File & " [Updated]"
If HeaderCountColPresent(HeaderList) = False Then File = File & " [Missing Column]"
frmMain.lstMergeFiles.AddItem File
File = Dir
Wend

'Select the first file if there are any
frmMain.lstMergeFiles.ListIndex = -1
If frmMain.lstMergeFiles.ListCount > 0 Then
frmMain.lstMergeFiles.ListIndex = 0
End If
End Sub

Function GetHeader(FilePath As String) As Variant
Dim FileH As Integer
Dim LineData As String
Dim InputChar As String

FileH = FreeFile
Open FilePath For Input Access Read As FileH
Do While Not EOF(FileH)
InputChar = Input(1, #1)
If InputChar = Chr(10) Then Exit Do
LineData = LineData & InputChar
Loop
Close FileH

'Get and spit header list
GetHeader = SplitLine(LineData, ",")
End Function

Function HeaderCountColPresent(HeaderList As Variant) As Boolean
Dim Index As Integer

HeaderCountColPresent = False
For Index = 0 To UBound(HeaderList)
If HeaderList(Index) = CHECKMARK_COUNT_COLUMN Then
HeaderCountColPresent = True
Exit For
End If
Next Index
End Function

Function HeaderUpdated(HeaderList As Variant) As Boolean
If HeaderList(UBound(HeaderList)) = CHECKMARK_HEADER Then
HeaderUpdated = True
Else
HeaderUpdated = False
End If
End Function

Sub UpdateMergeFile(MergePath As String, MergeFileName As String)
Dim MergeFileH As Integer
Dim FixedFileH As Integer
Dim LineData As String

Dim CountColumnIndex As Integer
Dim BGRPColumnIndex As Integer
Dim FUNDColumnIndex As Integer

Dim HeaderList As Variant
Dim RowData As Variant

Dim Index As Variant
Dim JIndex As Variant
Dim Temp As Variant

'Get mergefile handle and read in all data
MergeFileH = FreeFile
Open MergePath & MergeFileName For Input Access Read As MergeFileH
While Not EOF(MergeFileH)
LineData = LineData & Input(1, #1)
Wend
Close MergeFileH

'Get header list
HeaderList = SplitLine(Mid(LineData, 1, InStr(1, LineData, Chr(10)) - 1), ",")

'Locate Column last column with heading to assign values to
CountColumnIndex = -1
BGRPColumnIndex = -1
For Index = 0 To UBound(HeaderList)
If HeaderList(Index) = CHECKMARK_COUNT_COLUMN Then
CountColumnIndex = Index
End If
If HeaderList(Index) = BGRP_MESSAGES_COLUMN Then
BGRPColumnIndex = Index
End If
If HeaderList(Index) = FUND_MESSAGES_COLUMN Then
FUNDColumnIndex = Index
End If
Next Index

'Append new header
ReDim Preserve HeaderList(UBound(HeaderList) + 1)
HeaderList(UBound(HeaderList)) = CHECKMARK_HEADER

'Snip off Header information, leading chr(10)", and trailing "chr(10)
LineData = Mid(LineData, InStr(1, LineData, Chr(10)) + 2)
LineData = Left(LineData, Len(LineData) - 2)

'Populate RowData
Temp = SplitLine(LineData, """" & Chr(10) & """")
ReDim RowData(UBound(Temp))
For Index = 0 To UBound(Temp)
RowData(Index) = SplitLine(Temp(Index), """,""")
Next
Temp = Empty

'BEGIN MODIFICATION OF DB DUMP
'PART I - Append checkmark to each entry in RowData
For Index = 0 To UBound(RowData)
'Add column for checkmarks
Temp = RowData(Index)
ReDim Preserve Temp(UBound(Temp) + 1)
RowData(Index) = Temp

'Make array for count col data
Temp = SplitLine(RowData(Index)(CountColumnIndex), Chr(11))
For JIndex = 0 To UBound(Temp)
Temp(JIndex) = CHECKMARK_TOKEN
Next
RowData(Index)(UBound(RowData(Index))) = JoinArray(Temp, Chr(11))
Next
Temp = Empty

'Part II - WordWrap BGRP_MESSAGES
For Index = 0 To UBound(RowData)
'Replace all line returns with double spaces
RowData(Index)(BGRPColumnIndex) = StrReplace(RowData(Index)(BGRPColumnIndex), Chr(11), " ")
Next

'Part III - Add bullets to FUND_MESSAGES
For Index = 0 To UBound(RowData)
'Replace all line returns with double spaces
RowData(Index)(FUNDColumnIndex) = "

Discussion is locked

- Collapse -
Re: Microsoft macros created in OS 9 dont work in OS X
Dec 10, 2004 5:00AM PST

Cardenas,

Maybe better ask at the Macintosh forum also. This forum is heavily Windows based.

It could have to do something with filenames and separators. This little piece of code:
Case Is = "Macintosh"
DIR_SEPERATOR = ":"
Case Else
DIR_SEPERATOR = "\"
End Select

I suppose you didn't write this yourself. Why don't you ask the maker of the software?

Hope this helps.


Kees

- Collapse -
Re: Microsoft macros created in OS 9 dont work in OS X
Dec 10, 2004 3:24PM PST

Just as you mentioned that OSX is unix based it may not recognize your directory separators ":" and "\". If you know how Unix uses directoy separators then you could maybe change your Select Case like this:
Select Case ThisDocument.Application.System.OperatingSystem
Case Is = "Macintosh"
DIR_SEPERATOR = ":"
Case Is = "Windows"
DIR_SEPERATOR = "\"
Case Else
DIR_SEPARATOR = ","
End Select
for example if Unix uses a comma for a directory separator. Have a look in your C directory, if there's such an equivalent in Unix. Sorry but I don't have Unix, so I don't know how Unix looks like. And I just hope that Unix also understands Visual Basic.

Swisse

- Collapse -
Re: Microsoft macros created in OS 9 dont work in OS X
Dec 10, 2004 3:39PM PST

I just read a while ago that Unix uses a forward slash while Windows a backslash for directory separators. You could try changing your Select Case to:

Select Case ThisDocument.Application.System.OperatingSystem
Case Is = "Macintosh"
DIR_SEPERATOR = ":"
Case Is = "Windows"
DIR_SEPERATOR = "\"
Case Else
DIR_SEPARATOR = "/"
End Select

Swisse

- Collapse -
forward slash
Dec 14, 2004 8:41AM PST

First of all thanks for your help. So part of the problem is fixed by changing the code to.


Select Case ThisDocument.Application.System.OperatingSystem
Case Is = "Macintosh"
DIR_SEPERATOR = "/"
Case Else
DIR_SEPARATOR = "\"
End Select

So it no longer crashes the word application and it brings up the window that says update

Merge Updater
with two buttons Update Merge File (Grayed out)
and Refresh File List but when you click on the button it does not refresh the file list.

So the problem right now is that is does not show a list of files it can do the merge from.

- Collapse -
Re: Forward slash
Dec 14, 2004 3:59PM PST

You've got a nice problem now.

Possibly there are no files; that should be easy to check).

If you're sure there are files that should be shown, it's time to start debugging. Run step by step, find out what the code is supposed to do, and why it doesn't do it. But you have to have appropiate programming experience to do so, I'm afraid. Possibly find someone?

Or contact the maker, look at the FAQ section of the support site, search around with google (net, discussion groups). I'm sure you're not the only one with this problem.


Kees

- Collapse -
forward slash
Dec 15, 2004 5:55AM PST

Hello Cardenas,
I hope you don't mind but could you send us the document including the macro per email? But I can't promise you that I could solve this problem. I'll try to solve it, but there's no guarantee.

Swisse

- Collapse -
do you have an email I can send it to
Dec 16, 2004 4:15AM PST

Hi Swisse,

Do you have an email I can send it to?

Thanks

- Collapse -
Send me an email
Dec 16, 2004 6:29AM PST

Hello Cardenas,
Double click my name and when you come to my profile send me an email where I could send you my email address.

Swisse

- Collapse -
(NT) (NT) sent you an email yesterday 12/16/04
Dec 17, 2004 1:07AM PST
- Collapse -
(NT) (NT) Sent you my email address too.
Dec 17, 2004 6:20AM PST