我需要創建一個Excel VBA功能的幫助。Excel的VBA函數處理分隔符
字符串變量 「MyString的」 可以具有三種不同格式。
第一隻是一個普通的文本字符串。這種情況沒有必要。 需要的另外兩個版本來處理標籤和HREF鏈接在以後HTML輸出。
Excel的實例:
mystring = "This is a headline"
mystring = "<myLink href='some/link.html'</myLink> This is also a headline"
mystring = "<noLink href='#'</noLink> This is another headline"
所以,我需要確定字符串是否包含myLink的或noLink標籤和根據HREF到XML 分配href-attribute。 對於noLink它更用戶友好的只寫了<nolink>-tag
並讓功能添加href='#'
,我相信。
我願意接受建議,如果有更好的方法來設置這些分隔符。
而且,實際標題文字是XML標籤的一部分,後來用於mystringName XML屬性。
對於上面的例子,這些應該是生成的XML標籤:
<mytag mystringName="This is a headline"/>
<mytag mystringName="This is also a headline" href="some/link.html" />
<mytag mystringName="This is another headline" href="#" />
隨着XSL的幫助,那麼我可以用不同的href屬性的處理。
如何,我認爲這可能裏面VBA使用:
If mystring = "myLink" Then
xmf.writeline "<mytag mystringName=""" & mystring & """href= """ & href & """ > """
End If
我已經stumpled了this功能我在網上找到: 我需要寫的分隔符有點不同。 "<myLink href=some/link.html>"This is also a headline
也許這是一個很好的起點分裂的碎片,把它們放在一個陣列。
Public Function GetStringFromQuotation(ByRef sText, sDelimiter As String)
'Store the position of the 1st and 2nd delimiter in the String
Dim iPositionOfFirstDelimiter As Integer, iPositionOfSecondDelimiter As Integer
'Store the length of the delimiter
Dim iLenDelimiter As Integer
'Deliver nothing if the function doesn't get a single usable parameter
'otherwise you'd get an error later on
If Len(sText) = 0 And Len(sDelimiter) = 0 Then
GetStringFromQuotation = ""
Exit Function
End If
iLenDelimiter = Len(sDelimiter)
'Find 1st occurence of delimiter
iPositionOfFirstDelimiter = InStr(sText, sDelimiter)
'Find the 2nd one, starting right behind the first one
iPositionOfSecondDelimiter = InStr(iPositionOfFirstDelimiter + iLenDelimiter, _
sText, sDelimiter)
'If there are 2 occurences
If iPositionOfFirstDelimiter > 0 And iPositionOfSecondDelimiter > 0 Then
'Take the part of the string that's right between them
GetStringFromQuotation = Mid(sText, iPositionOfFirstDelimiter + iLenDelimiter, _
iPositionOfSecondDelimiter - iPositionOfFirstDelimiter - iLenDelimiter)
Else
GetStringFromQuotation = ""
End If
End Function
希望你能幫助我得到這個功能(或其他)的工作。
非常感謝。
非常感謝你 - 這不正是我想要 – TonyC