+ Reply to Thread
Results 1 to 17 of 17

macro save in two path different

Hybrid View

  1. #1
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    macro save in two path different

    Hello everyone.
    as correcting the part of the macro < if-then >:

    Sub CopiaESalvaInPathX()
     
       Dim username As String
           
    '-----------------------------------------------------------------------------------------
       username = Foglio5.Range("A2")
                   
     If xlExcel8 Then '<<< excel 2003
      
     sPath = "C:\Documents and Settings\" & username & "\Documenti\rapportini_ore_straordinarie" 'excel 2003
      
    Else
     
    If xlExcel8 Then '<<< excel 2007 e superiore ??????
     
    sPath = "C:\Users\" & username & "\Documents\rapportini_ore_straordinarie" 'excel 2007
     
    End If
    If Excel 2003 = sPath = "C:\Documents and Settings\" & username & "\Documenti\rapportini_ore_straordinarie" 'excel 2003

    if excel 2007 = sPath = "C:\Users\" & username & "\Documents\rapportini_ore_straordinarie" 'excel 2007

    I hope I was clear.
    max_max

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: macro save in two path different

    Sub CopiaESalvaInPathX()
     
       Dim username As String
           
    '-----------------------------------------------------------------------------------------
       username = Foglio5.Range("A2")
    
    Select Case Application.Version
        Case "11.0"
            sPath = "C:\Documents and Settings\" & username & "\Documenti\rapportini_ore_straordinarie" 'excel 2003
        Case "12.0"
            sPath = "C:\Users\" & username & "\Documents\rapportini_ore_straordinarie" 'excel 2007
    End Select
    
    End Sub
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: macro save in two path different

    Thanks daffodil11.
    The selection is automatically according to the installed version?
    The modification must run on excel 2003 and 2007
    A greeting and thanks.
    max_max
    Last edited by max_max; 07-01-2016 at 02:36 PM.

  4. #4
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: macro save in two path different

    It works well, I entered the exact change.
    Thanks daffodil 11.
    max_max
    Last edited by max_max; 07-01-2016 at 02:54 PM.

  5. #5
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: macro save in two path different

    A curiosity.
    If the application.version was superior to excel 2007 (I do not have a chance to try) the modification work?
    max_max

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: macro save in two path different

    No, but we can accommodate that as well.

    Sub CopiaESalvaInPathX()
     
       Dim username As String
           
    '-----------------------------------------------------------------------------------------
       username = Foglio5.Range("A2")
    
    Select Case Application.Version
        Case "8.0"  'Excel 97
        
        Case "9.0"  'Excel 2000
        
        Case "10.0" 'Excel 2002
        
        Case "11.0" 'Excel 2003
            sPath = "C:\Documents and Settings\" & username & "\Documenti\rapportini_ore_straordinarie" 'excel 2003
        Case "12.0" 'Excel 2007
            sPath = "C:\Users\" & username & "\Documents\rapportini_ore_straordinarie" 'excel 2007
        Case "14.0" 'Excel 2010
        
        Case "15.0" 'Excel 2013
        
        Case "16.0" 'Excel 2016
        
    End Select
    
    End Sub
    or you could just do a later or earlier than coercion

    Sub CopiaESalvaInPathX()
       Dim username As String
    '-----------------------------------------------------------------------------------------
       username = Foglio5.Range("A2")
    
    Select Case Application.Version
        
        Case "9.0", "10.0", "11.0" 'Excel 2003
            sPath = "C:\Documents and Settings\" & username & "\Documenti\rapportini_ore_straordinarie" 'excel 2003
        Case "12.0", "14.0", "15.0", "16.0" 'Excel 2007
            sPath = "C:\Users\" & username & "\Documents\rapportini_ore_straordinarie" 'excel 2007
        
    End Select
    End Sub

  7. #7
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: macro save in two path different


    Thank you so much daffobil11.
    A greeting.
    max_max
    ------------------------------------
    Ti ringrazio tantissimo daffobil11.
    Un saluto.
    max_max

  8. #8
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: macro save in two path different

    Hello can this change?

    Sub CopiaESalvaInPathX()
    
       Dim username As String
    
       username = Foglio5.Range("A2")
    
    
    Select Case  Application.OperatingSystem
    
    
        
        Case windows xp
    
            sPath = "C:\Documents and Settings\" & username & "\Documenti\rapportini_ore_straordinarie" 'excel 2003
    
        Case windows 7 / 8 / 10 
    
            sPath = "C:\Users\" & username & "\Documents\rapportini_ore_straordinarie" 'excel 2007
        
    End Select
    
    End Sub
    max_max
    Last edited by max_max; 07-02-2016 at 03:17 PM.

  9. #9
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: macro save in two path different

    Option Explicit
    Private Type OSVERSIONINFO
      dwOSVersionInfoSize As Long
      dwMajorVersion As Long
      dwMinorVersion As Long
      dwBuildNumber As Long
      dwPlatformId As Long
      szCSDVersion As String * 128
    End Type
    Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
    Public Function getVersion() As String
      Dim osinfo As OSVERSIONINFO
      Dim retvalue As Integer
      osinfo.dwOSVersionInfoSize = 148
      osinfo.szCSDVersion = Space$(128)
      retvalue = GetVersionExA(osinfo)
      getVersion = osinfo.dwMajorVersion & "." & osinfo.dwMinorVersion
    End Function
    
    Sub CopiaESalvaInPathX()
    
       Dim username As String
    
       username = Foglio5.Range("A2")
    
    
    Select Case getVersion
        
        Case 5.1 'xp
    
            sPath = "C:\Documents and Settings\" & username & "\Documenti\rapportini_ore_straordinarie" 'excel 2003
    
        Case Else '5.2 Windows Server 2003, 6.0 Windows Vista, 6.1 Windows 7, 6.2 Windows 8, 10.0 Windows 10
    
            sPath = "C:\Users\" & username & "\Documents\rapportini_ore_straordinarie" 'excel 2007
        
    End Select
    
    End Sub

  10. #10
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: macro save in two path different

    Thanks daffodil 11
    I think it's entirely accurate.
    I have to try the macro tomorrow morning.
    A greeting and thanks.
    max_max

  11. #11
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: macro save in two path different

    It was an interesting challenge! Glad to have helped.

  12. #12
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693
    Not work in window xp - excel 2003
    Work in Windows 7 - excel 2007
    max_max

  13. #13
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: macro save in two path different

    I will try harder!

  14. #14
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: macro save in two path different

    Hello daffodil 11
    After many tests I changed so:

    Option Explicit
    
    Private Type OSVERSIONINFO
    
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128
    End Type
    
    Private Declare Function GetVersionEx Lib "kernel32" _
          Alias "GetVersionExA" (lpVersionInformation As _
          OSVERSIONINFO) As Long
    
    
    Sub CopiaESalvaInPathX()
    
     Dim sPath As String
     Dim username As String
    
    '-------------------------------------------
    'versione windows
    Dim oOSInfo As OSVERSIONINFO
    oOSInfo.dwOSVersionInfoSize = Len(oOSInfo)
    GetVersionEx oOSInfo
    Dim Windows_version As String
                    'Windows_version = oOSInfo.dwMajorVersion & "." & oOSInfo.dwMinorVersion
    Windows_version = oOSInfo.dwMajorVersion
    '-------------------------------------------
               
            
      username = Foglio5.Range("A2")
      
    Select Case Windows_version
        
        Case 5 'xp
    
            sPath = "C:\Documents and Settings\" & username & "\Documenti\rapportini_ore_straordinarie" 'excel 2003
    
        Case Is > 5.1  'Windows Server 2003, 6.0 Windows Vista, 6.1 Windows 7, 6.2 Windows 8, 10.0 Windows 10
    
            sPath = "C:\Users\" & username & "\Documents\rapportini_ore_straordinarie" 'excel 2007
        
    End Select   
      
     End Sub
    and it is accurate or just a case of luck?
    max_max

  15. #15
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: macro save in two path different

    A little bit of both!

    I'm no VBA expert, I just know enough to be dangerous. Looks like you got it work just fine!

  16. #16
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: macro save in two path different

    The macros can be dangerous?

  17. #17
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: macro save in two path different

    I meant I know enough to do effective, yet basic tasks. I'm still terrible at many, many things in VBA.

    As a side note, VBA can be dangerous. THIS VBA macro is not dangerous. But even an antiquated programming language such as VBA can still do terrible, terrible things such as wipe computers, self-replicate, ie anything a normal computer virus does.

    This is why anytime you open a *.xlsm you do not recognize, you should first open it with macros disabled and examine the code and make sure none of the code is locked or hidden. Only allow macros to run on a unknown workbook when you are sure it poses no threat.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. macro save in path X
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-27-2016, 03:34 PM
  2. [SOLVED] Macro to save file to path automatically
    By pauldaddyadams in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-19-2015, 06:08 AM
  3. Macro to save as PDF to a changeable path
    By CRS111 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2015, 02:51 PM
  4. Save using macro file path
    By RANDY LIPOSKY in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2014, 11:10 AM
  5. [SOLVED] Macro to save xls to pdf with path & naming convention
    By graiggoriz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2014, 11:24 AM
  6. how to specify a file save path to a save macro
    By Solidstan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-04-2013, 05:33 PM
  7. [SOLVED] Macro to save as using path in worksheet
    By Shahid_Excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-03-2012, 08:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1