vba code in 365 gives error 13 in Excel 2007

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
128
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
My Dear Learned Friends.
Can any help be forthcoming with 2 problems I have. The first is that when the workbook is opened, no worksheet Tabs are visible. I have checked in the advanced section of the application, and tabs is selected.
problem 2 follows
The following code runs fine on "365" but on a users computer it stops at " fName = Sheets("Home").Range("Q2").Value" will not save the file as the code intended.
VBA Code:
Sub aSaveAs()
Dim MyFolder As String
Dim fName As String, ext As String
Dim TempFolder As String

 Application.DisplayAlerts = False
 
    MyFolder = Environ$("USERPROFILE") & "\Users\User\Documents\Excalibur Capital Kitchens\03_FactoryJobsAndCostings"
'C:\Users\User\Documents\Excalibur Capital Kitchens\03_FactoryJobsAndCostings
    If MyFolder = "" Then Exit Sub

    fName = Sheets("Home").Range("Q2").Value
Application.DisplayAlerts = True
    ActiveWorkbook.SaveAs Filename:=MyFolder & "\" & fName, _
         CreateBackup:=False

End Sub

I will of course be ever so grateful
kind regards
A
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
What is in the cell?
VBA Code:
Sheets("Home").Range("Q2")
 
Upvote 0
Solution
Yes I know that but what is it exactly
it is a filename derived from a quote or job number coupled with a Customers name and area description. So it will change all the time, but basically will read as Quote123_Jordan_Kitchen.xlsx
 
Upvote 0
So is "Quote123_Jordan_Kitchen.xlsx" exactly (without the quotes) what is in the cell when it is erring out?
How are you getting the filename in the cell (formula?)?
What happens if you change the line to...
VBA Code:
Sheets("Home").Range("Q2").Text
 
Upvote 0
it is a filename derived from a quote or job number coupled with a Customers name and area description. So it will change all the time, but basically will read as Quote123_Jordan_Kitchen.xlsx

I think @MARK858 is on the right track. If the cell has a formula error then it is possible that you may get 13-Runtime error. To test this, type "=1/0" in say cell A1 and then in VBA run the code

VBA Code:
Msgbox Range("A1").Value

1661201209099.png


I would recommend putting a breakpoint or introducing proper error handling to catch that error...
 
Upvote 0
So is "Quote123_Jordan_Kitchen.xlsx" exactly (without the quotes) what is in the cell when it is erring out?
How are you getting the filename in the cell (formula?)?
What happens if you change the line to...
VBA Code:
Sheets("Home").Range("Q2").Text
Thank you Mark and also Sid, Q2 is reflecting #NAME?, so there is a flaw in the way the name is being constructed. You guys have put me on the right track.....
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top