将文件保存到特定位置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将文件保存到特定位置相关的知识,希望对你有一定的参考价值。
我是VBA的新手我在Outlook VBA中有一个宏..我想将Excel文件保存到特定位置
答案
Sub List_Email_Info()
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As Long ' Row tracker
Dim arrHeader As Variant
Dim olNS As NameSpace
Dim olInboxFolder As MAPIFolder
Dim olItems As Items
Dim olMailItem As MailItem
Dim Cell As Range
Dim names As Variant
Dim c As Integer
arrHeader = Array("Subject", "id", "num", "nom", "ville")
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add
Set olNS = GetNamespace("MAPI")
Set olInboxFolder = olNS.GetDefaultFolder(olFolderInbox)
Set olItems = olInboxFolder.Items
i = 1
On Error Resume Next
xlWB.Worksheets(1).Range("A1").Resize(1, UBound(arrHeader) + 1).Value = arrHeader
For Each olMailItem In olItems
xlWB.Worksheets(1).Cells(i + 1, "A").Value = olItems(i).Subject
Do Until xlWB.Worksheets(1).Cells(i + 1, "A").Value = vbNullString
names = Split(xlWB.Worksheets(1).Cells(i + 1, "A").Value, ";")
For c = LBound(names) To UBound(names)
xlWB.Worksheets(1).Cells(i + 1, "A").Offset(0, c + 1).Value = names(c)
Next
xlWB.Worksheets(1).Cells(i + 1, "A").Offset(1, 0).Select ' Move to next row.
DoEvents
i = i + 1
Loop
Next olMailItem
Set xlWB = Nothing
Set xlApp = Nothing
Set olItems = Nothing
Set olI`enter code here`nboxFolder = Nothing
Set olNS = Nothing
End Sub
另一答案
尝试使用以下功能,
函数GetOutputName(作为字符串的可选sKeyword,作为字符串的可选sDateStamp)作为字符串
Dim sOutput As String
sDateStamp = Format(Now, "DDMMYYYY")
Select Case
Case 0
sOutput = "OutputFileName" & sDateStamp & ".xlsx"
Case Else
Call LogException("Invalid File Type when getting Output Name", "Report Type: " & g_iReportType, "There was an error defining the Output Name for this report. Please contact support.")
End Select
GetOutputName = sOutput
结束功能
以上是关于将文件保存到特定位置的主要内容,如果未能解决你的问题,请参考以下文章