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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,118
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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?
 

Forum statistics

Threads
1,136,445
Messages
5,675,900
Members
419,591
Latest member
mersanko

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
Top