Why won't this work?

mrphilk

Board Regular
Joined
Jun 6, 2010
Messages
75
Hi All,

I have this code from another project that I am trying to adapt for another, but for some reason it wont work. The original was written in Excel 2003, I am now using 2007.

=====

PHP:
Sub Generate_Office_Copy()

' On Error GoTo oops:

Dim Response As VbMsgBoxResult
Response = MsgBox("All entered information will now be saved as a New File." & vbCrLf & _
"Are you sure you want to continue?", vbQuestion + vbYesNo, "KHS Service Sheet Office Copy Generation")
If Response = vbNo Then Exit Sub

ActiveWorkbook.save

Dim newfile As String, ssno As String, eng As String, cust As String, loc As String

ssno = Range("Y2").Value
eng = Range("F19").Value
cust = Range("G44").Value
'loc = Range("j4").Value

newfile = ssno & ", " & eng & ", " & cust & "_" & " Service Report.xlsm"

ChDir ActiveWorkbook.Path

'  "C:\Documents and Settings\KHS\Desktop\Drafts"

ActiveWorkbook.SaveAs Filename:=newfile
    
' If Filename.newfile Then GoTo oops


    
MsgBox "Service Report Saved in the directory;" & vbCrLf & _
        vbCrLf & _
        ActiveWorkbook.Path & "\" & newfile & vbCrLf & _
        vbCrLf & _
        "PLEASE MAKE A NOTE OF THIS LOCATION FOR WHEN FOR FUTURE EDITING / MAILING!" & vbCrLf & _
         vbCrLf & "If you need to make further changes to this sheet then do so in the normal way (i.e file - save etc)" & _
         vbCrLf & _
         vbCrLf & _
         "=================[ NB: This is the OFFICCE COPY! ]================" & vbCrLf & _
         "If you need to make another Service Sheet please Re-open the MASTER DOCUMENT" _
         , vbQuestion + vbOKOnly, "Office Copy Created"
         
  ' ActiveWorkbook.Close
   
                       
 GoTo finished:
         
oops:

MsgBox ("The service sheet: " & newfile & " already exists" & vbCrLf & _
        vbCrLf & _
        "Please change the service sheet number and try again")
              
finished:

End Sub

It seems to be hanging on

PHP:
ActiveWorkbook.SaveAs Filename:=newfile

But I cant seem to see why, any ideas?

Also, how do I stop Excel from throwing up privacy errors because I am using macros every time I save?

Thanks!

:laugh:
 

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 are these values?
Rich (BB code):
ssno = Range("Y2").Value
eng = Range("F19").Value
cust = Range("G44").Value
 
Upvote 0
Genius! The last value was the date, didnt realise but it had `/` in it, so was not correct.

Thanks!

Any idea on the error message every time I save?
 
Upvote 0
Sorry I was vague on that issue, its the privacy warning but I've got rid under privacy options. I hate what they've done with office its like going back to school lol!

Im trying to get the date into the filename but this keeps throwing up a debug error.

I think its because the actual cell value is 01/01/2011, although I change the cell format to something which should be ok, ie

01 Jan 11

It still throws in an error, any ideas?

Thanks
 
Upvote 0
How about changing whatever ur cell is calling to as
Code:
.Text
instead of .Value

Try debugging it step by step and then seeing the value of ssno, eng, and cust

I'm quite confident that it has to do with the filename variable...
What are in the cells?
You need full path of the file you want to save to.. i.e C:\Windows\BlahbBlah\Hello.xls

Try looking if you have any of the following windows naming restricted characters in the filename
http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx
 
Upvote 0
Thats done it!


Thanks for that, also thanks for such a quick response!

Now on with the next issue lol! :-) :rofl:
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,683
Members
452,937
Latest member
Bhg1984

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