Why is folder creation macro causing Error Code 76? - excel

I am using some very basic coding to create folders and subfolders automatically. I understand the code isn't elegant however others should be able to maintain it.
The goal is to create a named folder on the desktop with name subfolders. The code works fine on my computer but is throwing an error 6 on other computers. Can you assist?
[Business_Name] is a named field in the spreadsheet
MkDir Environ("Userprofile") & "\Desktop\" & [Business_Name]
MkDir Environ("Userprofile") & "\Desktop\" & [Business_Name] & "\1. Sales"
MkDir Environ("Userprofile") & "\Desktop\" & [Business_Name] & "\1. Sales\1. Accepted Quote and Contract"
Thanks

Your code problem may be strictly connected to the path as it is built...
Sometimes, when (on the other computers) is OneDrive installed, the Desktop folder path includes OneDrive after User profile folder. It will be good to check this aspect... The error message will be elocvent for such a case (Run-Time Error 76, instead of 6).
Try, please
Debug.Print Environ("Userprofile") & "\Desktop\" & [Business_Name]: Stop
and see what it returns in Immediate Window...

Related

Excel error '1004' : Document not getting saved

I have a macro enabled excel file (loading large set of data) which is supposed to save a light version and a complete version of itself at one of my desktop location. This is done through referencing a cell in excel where complete path for those files are provided.
Error Image
The file was running fine for a while but all of a sudden started throwing 'Error 1004: Document not saved' on running the macro and not able to save the document. When I try to debug it, it stops at the 'ActiveWorkbook.Save' command.
ActiveWorkbook.Save
ChDir _
SharedDriveLocation
ActiveWorkbook.SaveAs Filename:= _
SharedDriveLocation & "Service Level Report.xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
I have already enabled all the trusted macro settings for the file. Nothing related to naming convention of file (already checked). Can someone please help understand if this could be excel version issue or something else? This file originated from someone else but I changed myself as the author of it. Assuming that has nothing to do with it.
Today I have had the same error. I found that in my case the file name wasn't correct. I put in full path name folder that doesn't exist.
Probably in your case is the same - incorrect Fullpath.
ActiveWorkbook.SaveAs Filename:= _
SharedDriveLocation & "Service Level Report.xlsm"
Try to change
ActiveWorkbook.SaveAs Filename:= _
SharedDriveLocation & "/" & "Service Level Report.xlsm"

Create new folder in the same folder where the current file is stored (in sharepoint)

I want to run the below VBA to create a new folder within the folder where the current file is stored. So far I have done this using the following simple VBA:
Sub Create_Folder()
MkDir Application.ThisWorkbook.Path & "\New Folder"
End Sub
Now, my company moved to sharepoint and when I run this VBA within a sharepoint folder I get runtime error 76.
I assume this is caused because ThisWorkbook.Path can not correctly identify the path anymore. Therefore, I checked how the path looks like:
https://company.sharepoint.com/sites/Finance1/Freigegebene Dokumente/Controlling/
In order to use this path I adjusted it in the VBA:
Sub Create_Folder()
WorkbookPath = ThisWorkbook.Path
WorkbookPath = "\\" & Replace(Split(WorkbookPath, "//")(1), "/", "\")
MkDir WorkbookPath & "\New Folder"
End Sub
However, I am still getting runtime error 76 when I try to create the new folder.
What is strange to me is that when I check the link in the windows explorer it loosk totally different to the link that I get with Application.ThisWorkbook.Path.
C:\Users\firstname.lastname\company\Controlling - Dokumente
Do you have any idea how I can solve this issue and create a new folder in the same folder where the current file is stored?

FileCopy - Automatically TRY AGAIN whenever an unexpected error occurs (0X8007003B)

I searched for hours but cannot find a solution. Hoping I can get the answer here.
I am doing a FileCopy through VBA and wants the code to automatically Try Again whenever an "unexpected network error has occurred" error happens. Can this be done via VBA?
Note that I have access to the network folder, the error is just common due to VPN connectivity issues.
file_ext = "*.xlsx"
FSO.CopyFile Source:=dummy_source_path & "\" & file_ext, _
Destination:=dummy_path

Trying to access other files in same folder but getting files outside folder

I'm trying to access all the other files in the same folder as the program but it wants to go to files in the entire directory. I get that's basically what I'm telling it to do but I'm still new to vba and don't know the syntax to accomplish what I want. Is there a way that I can get the current folder location from the program and have it go through all the files only in that folder?
Also I'd need a solution that doesn't use the Scripting.Object stuff since I'm running into issues with needing to downloading stuff for that and I feel uncomfortable requiring the people that will use this tool download things too especially since they'll be on secure .mil computers (as opposed to .com computers)
directory = ActiveWorkbook.Path 'Also tried CurDir()
fileName = Dir(directory & "*.xl??")
Do While fileName <> ""
...
fileName = Dir()
Loop
Try
ThisWorkbook.Path
MsgBox ThisWorkbook.Path ' Make sure its the right path...
and
Filename = Dir(directory & "\" & "*.xl??")

Excel VBA - URLDownloadToFile - Data missing in downloaded file

I am using the below code to download an excel file from a url. The URL (which I can not share here) is for a ticketing system. I used the search button in the website to get all open and in progress tickets. After that there is a Export drop down button and from the drop down I selected Excel. The url I used is the code is the url of this Export to Excel button.
The code is exporting the excel file to given path, but there is only the page header and footer data to show the time of download and two lines saying "Displaying 0 issues at 07/Jul/14 3:14 PM." and "No Issues Found". in the file.
If I use the url directly on any website, it opens the file with data. If I use Workbooks.open "myUrl" same blank file is opening.
Can anyone please check what is wrong?
Sub downloadFile()
Test = Dir("C:\Users\" & Environ("username") & "\" & "SearchResult.xls")
If Not Test = "" Then
Kill ("C:\Users\" & Environ("username") & "\" & "SearchResult.xls")
End If
mylink = ""
myresult = 0
mylink = "http://mylink.com/issueviews:SearchResult-excel-all-fields/temp/SearchResult.xls?jqlQuery=status+in+%28Open%2C+%22In+Progress%22%29&tempMax=1000"
myresult = URLDownloadToFile(0, mylink, "C:\Users\" & Environ("username") & "\" & "SearchResult.xls", 0, 0)
If myresult <> 0 Then
MsgBox "Error downloading " & mylink & Chr(10) & Error(myresult)
Else
MsgBox "File has been downloaded"
End If
End Sub
There is not enough information available from the data you have provided.
Basically there is some difference between what happens (on the HTTP protocol query/response level) when you use IE manually and when you run the code.
Typical things are redirecting status codes (see http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection) and missing authentication headers (see http://en.wikipedia.org/wiki/HTTP_header)
If you can not install tools (e.g. cURL) it will be difficult to guess as I don't know what kind of tools you have available.
There are some network diagnostics tools built right into web browsers (in Internet Explorer press F12, in Google Chrome press Ctrl+Shift+I)
(EDIT after comments) You can find what is the exact sequence of http requestes/responses exchanged between the web browser and the web server using the network tab in the browser's built-in developer tools.
Usage instructions for Google Chrome are at https://developer.chrome.com/devtools/docs/network#network-resource-details
Usage instructions for Internet Explorer are at http://msdn.microsoft.com/en-us/library/ie/dn255004(v=vs.85).aspx
Once you'll know what is the right sequence of messages try to reproduce it using cURL.
Once you succeed you can try to reproduce the sequence using Excel VBA functions with similar meaning or you can just call cURL command line tool from Excel as described here: Execute a command in command prompt using excel VBA (or in some of its linked or related questions)

Resources