Solved

Problem with file

Posted on 2015-02-04
4
85 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 29

Accepted Solution

by:
gowflow earned 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Pivot Table and column chart to display traffic by year 9 35
Tricky Shapes formula part 4 4 14
Excel Formula 6 25
Pivot Table Help 6 17
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

726 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