?
Solved

Problem with file

Posted on 2015-02-04
4
Medium Priority
?
87 Views
Last Modified: 2015-02-04
Hi,
when running these

Sub CreateNewFile()
    Dim objShtSrc As Excel.Worksheet
    Dim objShtDst As Excel.Worksheet
    
    Dim intCurRow As Integer
    
    VActiveWorkbookName = ActiveWorkbook.Name
    
    If VActiveWorkbookName <> "Test.xlsm" Then
        Exit Sub
    End If


'--------------
' Retrieve data
'--------------
    Worksheets("Details").Select
    Range("E5").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False

    Worksheets("Report").Select

    myPath = ActiveWorkbook.Path
    
    sFileName = myPath + "\Test " + Worksheets("Details").Range("B1").Value + ".xlsm"
    Set objFSO = Nothing
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(sFileName) Then
        objFSO.DeleteFile (sFileName)
    End If
    ActiveWorkbook.SaveAs Filename:= _
        sFileName _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
    MsgBox ("File saved!")
      
    Application.SendKeys "{ESC}"

End Sub

Open in new window


to create one other .xlsm file, using Excel 2010. The newly created file cannot be opened, as it says "... file format or file extension is not valid ..". what to adjust to the codes?
0
Comment
Question by:HuaMinChen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 31

Accepted Solution

by:
gowflow earned 1500 total points
ID: 40588313
replace this line
    ActiveWorkbook.SaveAs  Filename:= _
        sFileName _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False


By this line
    ActiveWorkbook.SaveAs  Filename:= _
        sFileName _
        ,  Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False

gowflow
0
 
LVL 12

Expert Comment

by:James Elliott
ID: 40588466
If that doesn't work, can you run & break the code on this line :

Set objFSO = Nothing

Open in new window


..and report back the value of sFileName
0
 
LVL 11

Expert Comment

by:jkpieterse
ID: 40588487
Replace xlNormal with xlOpenXMLWorkbookMacroEnabled
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 40588534
Might not be the case but line 25 of the code where you are creating the variable "sFileName" you have plus signs which in theory is adding the various items together; as they are text that will cause an error.

Try changing the plus signs to &:

sFileName = myPath & "\Test " & Worksheets("Details").Range("B1").Value & ".xlsm"

Thanks
Rob H
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

752 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