BarvoDelancy
New Member
- Joined
- Aug 28, 2019
- Messages
- 2
Hi everyone, new to the boards and stuck on resolving an error. Using O365 Excel. I first did anything with VBA five days ago, but I'm competent otherwise.
What I'm trying to do, and what happens when I do it
This is a fairly simple code that runs as a part of a larger process. The code copies a worksheet and then Saves As to a new filename.
I want to save to a onedrive location which is mapped on my local PC. The procedure runs, creates the sheet, saves it, and I get the following error:
If I save to a local location, there's no error. So the issue appears to be saving to a network location. Note that the file is successfully created and saved, even though the file says 'filename.xlsx - Save Failed'.
Here is the code I'm using:
Other Info
This is a piece of a larger process wherein the workbook creates forms, user fills in forms, and the forms populate some tables. (this works fine)
One of these tables is supposed to synchronize with Outlook to create events for each table row. My intended solution is to use Flow from O365 to do this. The complication is that Flow does not see .xlsm files as excel files, thus creating a copy of the worksheet with the table I need whenever we do an update. Flow then runs on a schedule to synch the calendar according to the copied file, which is why I want the file in a Onedrive location.
If there's a reasonable way to create Outlook events from excel using VBA I'm also open to that.
Thanks!
What I'm trying to do, and what happens when I do it
This is a fairly simple code that runs as a part of a larger process. The code copies a worksheet and then Saves As to a new filename.
I want to save to a onedrive location which is mapped on my local PC. The procedure runs, creates the sheet, saves it, and I get the following error:
Run-time error '1004':
Method 'SaveAs' of object '_Workbook' failed
If I save to a local location, there's no error. So the issue appears to be saving to a network location. Note that the file is successfully created and saved, even though the file says 'filename.xlsx - Save Failed'.
Here is the code I'm using:
Code:
Sub Export()
Dim fname As String
Dim fpath As String
Dim newbook As Workbook
Dim newfile As String
newfile = "[COLOR=#b22222]C:\pathname\filename.xlsx[/COLOR]"
fpath = "[COLOR=#b22222]C:\pathname[/COLOR]"
fname = "[COLOR=#b22222]Filename[/COLOR]" & ".xlsx"
Set newbook = Workbooks.Add
ThisWorkbook.Sheets("[COLOR=#b22222]SheetName[/COLOR]").Copy Before:=newbook.Sheets(1)
newbook.SaveAs filename:=newfile
End Sub
Other Info
This is a piece of a larger process wherein the workbook creates forms, user fills in forms, and the forms populate some tables. (this works fine)
One of these tables is supposed to synchronize with Outlook to create events for each table row. My intended solution is to use Flow from O365 to do this. The complication is that Flow does not see .xlsm files as excel files, thus creating a copy of the worksheet with the table I need whenever we do an update. Flow then runs on a schedule to synch the calendar according to the copied file, which is why I want the file in a Onedrive location.
If there's a reasonable way to create Outlook events from excel using VBA I'm also open to that.
Thanks!