Невозможно добавить некоторые значения при преобразовании Excel в VCF с использованием VBA. - PullRequest
0 голосов
/ 30 октября 2018

Я пытаюсь преобразовать свой файл Excel в VCF. Но я не могу добавить факс и адрес в формате VCF. Остальные значения я могу конвертировать, но не могу добавить факс и адрес в VCF. Мой код указан ниже:

Sub excelTovcf()
    Dim FileNum As Integer
    Dim iRow As Integer
    Dim FirstName As String
    Dim LastName As String
    Dim FullName As String
    Dim EmailAddress As String
    Dim PhoneHome As String
    Dim PhoneWork As String
    Dim Organization As String
    Dim JobTitle As String

    iRow = 7
    ' set a unique integer for the new
    ' text file
    FileNum = FreeFile
    ' Save this vcf file on desktop
    OutFilePath = VBA.Environ$("UserProfile") & "\Desktop\MyContacts.VCF"
    Open OutFilePath For Output As FileNum

    With Sheets("contacts")
    While VBA.Trim(.Cells(iRow, 1)) <> ""
        FirstName = VBA.Trim(.Cells(iRow, 1))
        LastName = VBA.Trim(.Cells(iRow, 2))
        FullName = VBA.Trim(.Cells(iRow, 3))
        EmailAddress = VBA.Trim(.Cells(iRow, 4))
        PhoneHome = VBA.Trim(.Cells(iRow, 5))
        PhoneWork = VBA.Trim(.Cells(iRow, 6))
        Organization = VBA.Trim(.Cells(iRow, 7))
        JobTitle = VBA.Trim(.Cells(iRow, 8))
        Fax = VBA.Trim(.Cells(iRow, 9))
        Address = VBA.Trim(.Cells(iRow, 15))



    ' Start printing the data in above specified
    ' format of VCF file format
        Print #FileNum, "BEGIN:VCARD"
        Print #FileNum, "VERSION:3.0"
        Print #FileNum, "N:" & FirstName & ";" & LastName & ";;;"
        Print #FileNum, "FN:" & FullName
        Print #FileNum, "ORG:" & Organization
        Print #FileNum, "TITLE:" & JobTitle
        Print #FileNum, "TEL;TYPE=HOME,VOICE:" & PhoneWork
        Print #FileNum, "TEL;TYPE=WORK,VOICE:" & PhoneHome
        Print #FileNum, "TEL,TYPE=WORK,FAX:" & Fax
        Print #FileNum, "EMAIL:" & EmailAddress
        Print #FileNum, "END:VCARD"
        iRow = iRow + 1
    Wend
 End With
    'Close The File
    MsgBox "Total " & iRow - 7 & " Contacts are exported to VCF File. It is saved on your Desktop"
    Close #FileNum
End Sub

Нужна помощь, как я могу добавить факс и адрес в VCF из моего файла Excel. Я новичок, поэтому не могу решить эту проблему.

1 Ответ

0 голосов
/ 31 октября 2018

Согласно моему комментарию, я думаю, что следующие операторы Print будут работать -

Print #FileNum, "BEGIN:VCARD"
Print #FileNum, "VERSION:3.0"
Print #FileNum, "N:" & FirstName & ";" & LastName & ";;;"
Print #FileNum, "FN:" & FullName
Print #FileNum, "ORG:" & Organization
Print #FileNum, "TITLE:" & JobTitle
Print #FileNum, "TEL;TYPE=HOME,VOICE:" & PhoneWork
Print #FileNum, "TEL;TYPE=WORK,VOICE:" & PhoneHome
Print #FileNum, "TEL;TYPE=WORK,FAX:" & Fax
Print #FileNum, "EMAIL:" & EmailAddress
Print #FileNum, "ADR;TYPE=HOME:" & Address
Print #FileNum, "END:VCARD"
iRow = iRow + 1

Имейте в виду, строка Address должна выглядеть примерно так:

LINE1;LINE2;LINE3;LINE4;LINE5;ZIP/POSTCODE;COUNTRY

Таким образом, вам может потребоваться Replace коды возврата в ячейке с точками с запятой, если адрес находится в одной ячейке.

...