ThisWorkbook.Path for Mac返回(错误68)

时间:2014-10-11 00:23:50

标签: excel macos excel-vba vba

我下载的电子表格似乎最初是针对Windows编写的。该文件位于http://www.automateexcel.com/2004/12/15/create_an_rss_feed_with_excel/

对于行RssLocation = ThisWorkbook.Path& “\”& FeedSheet.Cells(5,2).Value

我用“/user/desktop/rsscreate.xlsm”替换了“\”,但我仍然收到错误。 我也尝试过“& Application.PathSeparator&”但仍然是错误。

有什么建议吗?

宏的代码如下。


Sub WriteRss()
Dim X As Long
Dim FeedSheet As Worksheet

Dim RssLocation As String
Dim DomainName As String
Dim DomainDescription As String
Dim DomainTitle As String

    'Change the word "Sheet1" to the tabname of
    'the sheet where you keep your feeds list
    Set FeedSheet = Sheets("Sheet1")

    'Your domain name(include the http://)
    DomainName = FeedSheet.Cells(2, 2).Value

    'Your Site's Title
    DomainTitle = FeedSheet.Cells(3, 2).Value

    'Your Site's Description
    DomainDescription = FeedSheet.Cells(4, 2).Value

    'Location to write file, defaults to workbook directory
    RssLocation = ThisWorkbook.Path & "\" & FeedSheet.Cells(5, 2).Value

    'Kill the file if it already exists
    If Len(Dir(RssLocation)) > 0 Then
        Kill RssLocation
    End If

    Open RssLocation For Append As #1
    Print #1, "<?xml version=""1.0""" & " encoding=""iso-8859-1""?>"
    Print #1, "<rss version=" & """" & "2.0" & """" & _
              " xmlns:content = ""http:" & _
              "//purl.org/rss/1.0/modules/content/"">"
    Print #1, "    <channel>"
    Print #1, "    <title>" & DomainTitle & "</title>"
    Print #1, "    <link>" & DomainName & "</link>"
    Print #1, "    <description>" & DomainDescription & "</description>"
    Print #1, "    <language>en-us</language>"

    'Loop through sheet specified
    'Start @ row 2
    'ColumnA=Title, ColumnB=Link, ColumnC=Description

    For X = 9 To FeedSheet.Range("A" & FeedSheet.Rows.Count) _
        .End(xlUp).Row
        Print #1, "    <item>"
        Print #1, "      <title>" & FeedSheet.Cells(X, 1).Value & _
                  "</title>"
        Print #1, "      <link>" & FeedSheet.Cells(X, 2).Value & _
                  "</link>"
        Print #1, "<description>"
        Print #1, "<![CDATA["
        Print #1, FeedSheet.Cells(X, 3).Value
        Print #1, "  ]]> "
        Print #1, "</description>"
        Print #1, "    </item>"
    Next

    Print #1, "  </channel>"
    Print #1, "</rss>"
    Close #1
MsgBox "Your new RSS feed can be found here: " & RssLocation
End Sub

Sub InsertNew()
    Range("A9:C17").Select
    Selection.Cut
    Range("A10:C18").Select
    ActiveSheet.Paste
    Range("A18:C18").Select
    Selection.Copy
    Range("A9:C9").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
End Sub

编辑:在“答案”部分添加以下内容。

我在之前的回答中尝试了代码。我仍在第If Len(Dir(RssLocation)) > 0

收到错误

有关如何使用MacId和ThisWorkbook.Path而不是Applcaton.PathSeparator的任何建议? Siddharth你的想法?

1 个答案:

答案 0 :(得分:0)

试试这个(未经测试)

RssLocation = ThisWorkbook.Path & "\" & FeedSheet.Cells(5, 2).Value
RssLocation = Replace(RssLocation ,"\", Application.PathSeparator)
'Debug.Print RssLocation