Results 1 to 5 of 5

How Do I User Windows Variable Username with strFilePath?

Threaded View

kitchenspoon How Do I User Windows... 04-19-2016, 03:53 AM
grimes0332 Re: How Do I User Windows... 04-19-2016, 04:07 AM
kitchenspoon Re: How Do I User Windows... 04-19-2016, 04:14 AM
grimes0332 Re: How Do I User Windows... 04-19-2016, 04:22 AM
kitchenspoon Re: How Do I User Windows... 04-19-2016, 04:30 AM
  1. #1
    Registered User
    Join Date
    04-30-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    8

    How Do I User Windows Variable Username with strFilePath?

    Hi,

    I am trying to change the destination of this command. Typically every Windows user on Windows 7 or later has the filepath C:\User\{username}\Desktop Folder. And this is where i want the file to export the PDF to.

    Here is my code

    Option Explicit
    Sub SaveSheetsAsPDF()
    
        Dim wksAllSheets As Variant
        Dim wksSheet1 As Worksheet
        Dim strFilename As String, strFilepath As String
        
        'Set references up-front
        Set wksSheet1 = ThisWorkbook.Sheets("Helvar Snags")
        wksAllSheets = Array("Helvar Snags", "Yes", "No")
        strFilepath = "C:\Helvar Snags\"
        
        'Create the full Filename using cells D6, E6 and F6
        With wksSheet1
        
            'Assemble the string cell-by-cell, "D6 E6-F6"
            strFilename = strFilepath & .Range("D11").Value & " " & _
                                        .Range("C1").Value & "-" & _
                                        .Range("F31").Value & ".pdf"
            
        End With
        
        'Save the Array of worksheets (which will be selected) as a PDF
        ThisWorkbook.Sheets(wksAllSheets).Select
        wksSheet1.ExportAsFixedFormat _
                  Type:=xlTypePDF, _
                  Filename:=strFilename, _
                  Quality:=xlQualityStandard, _
                  IncludeDocProperties:=True, _
                  IgnorePrintAreas:=False, _
                  OpenAfterPublish:=True
                  
        'Make sure all the worksheets are NOT left selected
        wksSheet1.Select
    
    End Sub

    Currently my save file path is "C:\Helvar Snags\" a folder of which the engineer or project engineer would need to create themselves or it simply will not output. By using the desktop folder, the sheet will always output. I have alleviated the issue of having the same file name as the strFilepath Ranges D11,C1,F31 are "project names, dates and times" which constantly change as i have converted the date and the time to a numerical.

    Any and all help would be greatly appreciated, proper headscratcher this.

    The link of the template is below

    Link: https://www.dropbox.com/s/cbtpv9sxv1...heet.xlsm?dl=0

    The module to look at is Module 18.

    Cheers All
    Attached Files Attached Files
    Last edited by kitchenspoon; 04-19-2016 at 03:57 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. windows username
    By max_max in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-18-2013, 05:07 PM
  2. getting windows username into excel
    By Billy_E in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2013, 12:53 PM
  3. [SOLVED] Saving a file to a specific name to a folder with a windows username
    By wagwagdude in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2013, 06:13 PM
  4. Get Actual Windows Username
    By RedWing in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2012, 08:11 PM
  5. Insert user's name into cell based on windows user login when a button is clicked.
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 08-16-2011, 01:08 PM
  6. SQL Statement WHERE User = Windows Username ID
    By JohnGaltnl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2011, 04:24 AM
  7. windows 2003 server username
    By neta in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2008, 08:07 AM
  8. [SOLVED] Windows API to get network username of person with file open
    By Paul Martin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-02-2005, 12:35 PM

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