|
自用多年的很实用的代码,稍微整理一下开起来更加简洁
作用生成VCF 文件 两种格式 1种是用于 360手机助手的(其他的手机助手也许通用,没测试过)
1种是 存入手机TF卡中,用手机的文件浏览器找到点击自动导入的
格式支持4个电话 一个邮箱,一个地址,一个分组信息,对于大多数人来说足够用了
贴个代码放这,注视中也有一些说明
- Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
- Function VbStrToMultiByte(VbStr As String) As Byte()
- Dim bufSize As Long
- Dim arr() As Byte
- bufSize = WideCharToMultiByte(65001, 0&, StrPtr(VbStr), Len(VbStr), 0, 0, 0, 0)
- ReDim arr(bufSize - 1)
- WideCharToMultiByte 65001, 0&, StrPtr(VbStr), Len(VbStr), arr(0), bufSize, 0, 0
- VbStrToMultiByte = arr
- '这几行代码以及上述API所起到的作用就是 手工另存为 UTF-8格式
- End Function
- Sub toANSI() '360助手 安卓系统 ANSI格式通过手机助手导入
- Dim s As String, b() As Byte, b1() As Byte, s1 As String
- For i = 2 To 6 '从第二行开始到第六行,根据实际情况修改
- s1 = s1 & "BEGIN:VCARD" & vbCrLf & "VERSION:3.0" & vbCrLf
- s1 = s1 & "CATEGORIES:" & Cells(i, 8) & vbCrLf
- s1 = s1 & "N:" & Cells(i, 1) & vbCrLf
- s1 = s1 & "TEL;TYPE=CELL:" & Cells(i, 2) & vbCrLf
- s1 = s1 & "TEL;TYPE=CELL:" & Cells(i, 3) & vbCrLf
- s1 = s1 & "TEL;TYPE=WORK:" & Cells(i, 4) & vbCrLf
- s1 = s1 & "TEL;TYPE=HOME:" & Cells(i, 5) & vbCrLf
- s1 = s1 & "EMAIL;TYPE=PREF:" & Cells(i, 6) & vbCrLf
- s1 = s1 & "ADR;TYPE=WORK:" & Cells(i, 7) & vbCrLf
- s1 = s1 & "END:VCARD" & vbCrLf
- Next
- b1 = StrConv(s1, 128)
- s = "c:\360手机助手导入.vcf"
- If Dir(s) <> "" Then Kill s
- Open s For Binary As 1
- Put 1, , b1
- Close
- MsgBox s
- End Sub
- Sub toUTH8() '' 安卓系统 Utf-8格式,直接存在手机卡中导入
- Dim s As String, b() As Byte, b1() As Byte, s1 As String
- For i = 2 To 6 '从第二行开始到第六行,根据实际情况修改
- s1 = s1 & "BEGIN:VCARD" & vbCrLf & "VERSION:3.0" & vbCrLf
- s1 = s1 & "CATEGORIES:" & Cells(i, 8) & vbCrLf '分组信息,某些机型会忽略此项,如果重要最好用手机助手导入
- s1 = s1 & "N:" & Cells(i, 1) & vbCrLf
- s1 = s1 & "TEL;TYPE=CELL:" & Cells(i, 2) & vbCrLf
- s1 = s1 & "TEL;TYPE=CELL:" & Cells(i, 3) & vbCrLf
- s1 = s1 & "TEL;TYPE=WORK:" & Cells(i, 4) & vbCrLf
- s1 = s1 & "TEL;TYPE=HOME:" & Cells(i, 5) & vbCrLf
- s1 = s1 & "EMAIL;TYPE=PREF:" & Cells(i, 6) & vbCrLf
- s1 = s1 & "ADR;TYPE=WORK:" & Cells(i, 7) & vbCrLf
- s1 = s1 & "END:VCARD" & vbCrLf
- Next
- b1 = VbStrToMultiByte(s1) '
- '所有语句都相同,只是在这里进行格式转换 ,相当于手工另存为UTF-8格式
- s = "c:\直接存在手机卡中导入.vcf"
- If Dir(s) <> "" Then Kill s
- Open s For Binary As 1
- Put 1, , b1
- Close
- MsgBox s
- End Sub
复制代码
手机联系人.rar
(9.79 KB, 下载次数: 668)
|
|