Excel to vcf

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
139
I'm trying to produce a .vcf file for each line of data in an Excel file but running into runtime error 52 at the line Print #FileNum, "BEGIN:VCARD"

The spreadsheet has Latitude in col A
Longitude in Col b
Name in col C
Phone number in col D

VBA Code:
ub Create_vcf_File()

Dim r, FileNum  As Integer
Dim myfile As String
Dim mypath As String
Dim Data, LastRow As Long
Sheets("National Trust").Select

mypath = "E:\Car\Destination files\Destinations"

 With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    
For r = 2 To LastRow
myfile = Cells(r, "C")

Print #FileNum, "BEGIN:VCARD"
Print #FileNum, "VERSION:3.0"
Print #FileNum, "N:" & Cells(r, "C")
Print #FileNum, "GEO" & Cells(r, "A") & Cells(r,"B")
Print #FileNum, "TEL;TYPE=WORK:" & Cells(r, "D")
Print #FileNum, "END:VCARD"

Open mypath & myfile & ".vcf" For Append As #1
Print #1, Data
Close #1
Data = ""
Next r

End Sub

What's causing the error?

Thanks
Geoff
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You haven't assigned a value to FileNum. You're missing a statement like:

Code:
FileNum = FreeFile

And then you need to open the file before you write to it. The rest of the code appears to all be out of order to me, and data has no value?
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,742
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top