gpt4 book ai didi

excel - 连接两个路径字符串以获得最终路径?

转载 作者:行者123 更新时间:2023-12-04 19:52:40 24 4
gpt4 key购买 nike

我正在尝试将 excel 文件保存到特定路径。所以基本上,当我单击按钮时,我正在创建一个文件夹,并希望将文件保存在该文件夹中。创建的文件夹以当前月份作为名称。我正在尝试保存到当前月份的文件夹中。

    'Create folder as Month Name. Save filename as date inside "month".
Dim sDate As String = DateTime.Now.ToString("yyyy-MM-dd") & "_" & DateTime.Now.ToString("HH-mm-ss")
Dim sMonth As String = DateTime.Now.ToString("MMMM")
Dim sFolder = Application.StartupPath & "\Resources\Excel\"


My.Computer.FileSystem.CreateDirectory(sFolder & Format(sMonth))

Dim sfinal = Path.Combine(sFolder, sMonth)
xlSh.SaveAs(sfinal & Format(sDate) & ".xlsx")

xlApp.Workbooks.Close()
xlApp.Quit()

事实上,这段代码没有给我任何错误。但是,它没有创建名为“March”<-current month 的文件夹并保存在其中,而是将文件保存在\Excel\中,并且还在同一位置创建了文件夹。

最佳答案

您可以使用以下函数(类似于 .NET System.IO.Path.Combine)

Function PathCombine(path1 As String, path2 As String)

Dim combined As String

combined = path1
If Right$(path1, 1) <> Application.PathSeparator Then
combined = combined & Application.PathSeparator
End If
combined = combined & path2
PathCombine = combined

End Function

希望这对您有所帮助!

关于excel - 连接两个路径字符串以获得最终路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28995231/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com