Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Save as code error

Posted on 2011-05-06
4
Medium Priority
?
154 Views
Last Modified: 2012-08-14
Hi,

I have some code which attempts to save a file as a CSV, when i run it, i get the attached  error message

The folder is not read only, is there any error in the code?

Thanks
Seamus

Sub CreateFile()
Dim strFile As String
strFile = Date_FileName("\\ukhibmdata02\RIGHTS\Eurobond\COUPONS\CouponTickets\Coupons 2011\Output\", "Treats Seamus MTN For Merit ")

If Dir(strFile) <> "" Then
   If MsgBox("File already exists - overwrite?", vbYesNo) = vbYes Then
      Kill strFile
      

   Else
      Exit Sub
   End If
End If
ActiveWorkbook.SaveAs Filename:= _
strFile, _
FileFormat:=xlCSV, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False



End Sub

Function Date_FileName(pPath As String, pFilePrefix As String) As String
Dim DayOfWeek As Integer, DayDiff As Integer, CharDate As String, MonthNo As Integer, CharYear As String, CharMonth  As String
Dim Result As String
    
    DayOfWeek = Weekday(Date)                                   ' Sunday is 1, Monday is 2, Tuesday is 3 etc
    If DayOfWeek = 2 Then                                       ' If a monday then we need the date as of friday, otherwise previous day
        DayDiff = 3
    Else
        If DayOfWeek = 1 Then
          DayDiff = 2                                           ' If a Sunday then we need the date as of friday, otherwise previous day
        Else
          DayDiff = 1                                           ' otherwise it should be set to the previous day
        End If
    End If
    CharDate = Format(Date - DayDiff, "ddmmyyyy")               ' Get the character date formwatted how we want it

    CharMonth = Format(Date - DayDiff, "m mmm yy")
    Result = pPath & CharMonth & "\" & pFilePrefix & "" & CharDate & ".CSV"
    Date_FileName = Result
End Function

Open in new window

Doc4.doc
0
Comment
Question by:Seamus2626
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
leonstryker earned 1000 total points
ID: 35708767
Try saving in a different folder. Does that generate an error?

Leon
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 35708774
Some other things to try:

Shorter name and no spaces in the file name.
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 1000 total points
ID: 35726604
If you add a Msgbox strFile line, is the path that comes up correct? Does the date folder already exist?
0
 

Author Closing Comment

by:Seamus2626
ID: 35728495
all sorted guys, thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question