PC Review


Reply
Thread Tools Rate Thread

difficulties using vba to save to the desktop

 
 
=?Utf-8?B?QXJpZWxadXN5YQ==?=
Guest
Posts: n/a
 
      6th Nov 2007
I've got a quirky problem. The network admin folks here at my office have a
bit of a strange naming convention for users. If you start as a part timer
you get a username that looks something like pt[loc][initials] so for someone
who is named John H. Smith starting part time at location number 04, his
login would be pt04jhs. The trouble is that if John switches to full time
his username changes to ft04jhs but his userprofile still points to the
directory C:\documents and settings\pt04jhs\. I want to use vba to export
(copy) a sheet from the workbook I'm in to a new workbook, save that workbook
to the desktop, and close that workbook without prompting the user.
(Incidentally, the rest of the naming convention for the file relies on a
combo box on the main menu (frmMainMenu) form called cmbSelectDivision, just
in case you're wondering why that's in there.) Here's my code right now:

dim NameThatExport as string
NameThatExport = "Division" +
frmMainMenu.cmbSelectDivision.Value _
+ ".xls"
Sheets("MyList").Select
Sheets("MyList").Copy
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\" + Environ("username") _
+ "\Desktop\" + NameThatExport, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False _
Windows(fileNm).Activate
Application.CutCopyMode = False
ActiveWorkbook.Close False


The code works well for users who started full time and remained full time
and for users who started part time and remained part time but for those who
started part time and switched to full time they get no autonaming. Is there
a way to use code to find the desktop other than the way I tried above?
Thanks for your help!
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QXJpZWxadXN5YQ==?=
Guest
Posts: n/a
 
      6th Nov 2007
oops...

Windows(fileNm).Activate

should have read

Windows(NameThatExport).Activate

That's what I get for typing the code from memory rather than copying and
pasting.

"ArielZusya" wrote:

> I've got a quirky problem. The network admin folks here at my office have a
> bit of a strange naming convention for users. If you start as a part timer
> you get a username that looks something like pt[loc][initials] so for someone
> who is named John H. Smith starting part time at location number 04, his
> login would be pt04jhs. The trouble is that if John switches to full time
> his username changes to ft04jhs but his userprofile still points to the
> directory C:\documents and settings\pt04jhs\. I want to use vba to export
> (copy) a sheet from the workbook I'm in to a new workbook, save that workbook
> to the desktop, and close that workbook without prompting the user.
> (Incidentally, the rest of the naming convention for the file relies on a
> combo box on the main menu (frmMainMenu) form called cmbSelectDivision, just
> in case you're wondering why that's in there.) Here's my code right now:
>
> dim NameThatExport as string
> NameThatExport = "Division" +
> frmMainMenu.cmbSelectDivision.Value _
> + ".xls"
> Sheets("MyList").Select
> Sheets("MyList").Copy
> ActiveWorkbook.SaveAs Filename:= _
> "C:\Documents and Settings\" + Environ("username") _
> + "\Desktop\" + NameThatExport, FileFormat:=xlNormal, _
> Password:="", WriteResPassword:="", _
> ReadOnlyRecommended:=False, CreateBackup:=False _
> Windows(fileNm).Activate
> Application.CutCopyMode = False
> ActiveWorkbook.Close False
>
>
> The code works well for users who started full time and remained full time
> and for users who started part time and remained part time but for those who
> started part time and switched to full time they get no autonaming. Is there
> a way to use code to find the desktop other than the way I tried above?
> Thanks for your help!

 
Reply With Quote
 
Steve Yandl
Guest
Posts: n/a
 
      6th Nov 2007
Here is one option to return the path to the current user's desktop as a
string.

Set objShell = CreateObject("Shell.Application")
Set objFolderDsk = objShell.Namespace(&H10&)
strDsk = objFolderDsk.Self.Path
MsgBox strDsk
Set objShell = Nothing

Steve



"ArielZusya" <(E-Mail Removed)> wrote in message
news:040D98DB-C4DC-47A7-95DF-(E-Mail Removed)...
> I've got a quirky problem. The network admin folks here at my office have
> a
> bit of a strange naming convention for users. If you start as a part
> timer
> you get a username that looks something like pt[loc][initials] so for
> someone
> who is named John H. Smith starting part time at location number 04, his
> login would be pt04jhs. The trouble is that if John switches to full time
> his username changes to ft04jhs but his userprofile still points to the
> directory C:\documents and settings\pt04jhs\. I want to use vba to export
> (copy) a sheet from the workbook I'm in to a new workbook, save that
> workbook
> to the desktop, and close that workbook without prompting the user.
> (Incidentally, the rest of the naming convention for the file relies on a
> combo box on the main menu (frmMainMenu) form called cmbSelectDivision,
> just
> in case you're wondering why that's in there.) Here's my code right now:
>
> dim NameThatExport as string
> NameThatExport = "Division" +
> frmMainMenu.cmbSelectDivision.Value _
> + ".xls"
> Sheets("MyList").Select
> Sheets("MyList").Copy
> ActiveWorkbook.SaveAs Filename:= _
> "C:\Documents and Settings\" + Environ("username") _
> + "\Desktop\" + NameThatExport, FileFormat:=xlNormal, _
> Password:="", WriteResPassword:="", _
> ReadOnlyRecommended:=False, CreateBackup:=False _
> Windows(fileNm).Activate
> Application.CutCopyMode = False
> ActiveWorkbook.Close False
>
>
> The code works well for users who started full time and remained full time
> and for users who started part time and remained part time but for those
> who
> started part time and switched to full time they get no autonaming. Is
> there
> a way to use code to find the desktop other than the way I tried above?
> Thanks for your help!



 
Reply With Quote
 
=?Utf-8?B?QXJpZWxadXN5YQ==?=
Guest
Posts: n/a
 
      6th Nov 2007
Thanks Steve. Incidentally, is there any disadvantage to using this method
vs using the environ method? After posting I changed my search tactic and
discovered a list of environ variables and discovered I could use
"userprofile" to return everything before "\desktop\" but before I decide
which method to use I thought I'd ask if one is better or faster or otherwise
preferable. Thanks!

"Steve Yandl" wrote:

> Here is one option to return the path to the current user's desktop as a
> string.
>
> Set objShell = CreateObject("Shell.Application")
> Set objFolderDsk = objShell.Namespace(&H10&)
> strDsk = objFolderDsk.Self.Path
> MsgBox strDsk
> Set objShell = Nothing
>
> Steve
>
>
>
> "ArielZusya" <(E-Mail Removed)> wrote in message
> news:040D98DB-C4DC-47A7-95DF-(E-Mail Removed)...
> > I've got a quirky problem. The network admin folks here at my office have
> > a
> > bit of a strange naming convention for users. If you start as a part
> > timer
> > you get a username that looks something like pt[loc][initials] so for
> > someone
> > who is named John H. Smith starting part time at location number 04, his
> > login would be pt04jhs. The trouble is that if John switches to full time
> > his username changes to ft04jhs but his userprofile still points to the
> > directory C:\documents and settings\pt04jhs\. I want to use vba to export
> > (copy) a sheet from the workbook I'm in to a new workbook, save that
> > workbook
> > to the desktop, and close that workbook without prompting the user.
> > (Incidentally, the rest of the naming convention for the file relies on a
> > combo box on the main menu (frmMainMenu) form called cmbSelectDivision,
> > just
> > in case you're wondering why that's in there.) Here's my code right now:
> >
> > dim NameThatExport as string
> > NameThatExport = "Division" +
> > frmMainMenu.cmbSelectDivision.Value _
> > + ".xls"
> > Sheets("MyList").Select
> > Sheets("MyList").Copy
> > ActiveWorkbook.SaveAs Filename:= _
> > "C:\Documents and Settings\" + Environ("username") _
> > + "\Desktop\" + NameThatExport, FileFormat:=xlNormal, _
> > Password:="", WriteResPassword:="", _
> > ReadOnlyRecommended:=False, CreateBackup:=False _
> > Windows(fileNm).Activate
> > Application.CutCopyMode = False
> > ActiveWorkbook.Close False
> >
> >
> > The code works well for users who started full time and remained full time
> > and for users who started part time and remained part time but for those
> > who
> > started part time and switched to full time they get no autonaming. Is
> > there
> > a way to use code to find the desktop other than the way I tried above?
> > Thanks for your help!

>
>
>

 
Reply With Quote
 
Steve Yandl
Guest
Posts: n/a
 
      6th Nov 2007
I'd probably use environ since it would spare the overhead of creating the
Shell.Application object. I work more with vbs than VBA so I tend to be
more familiar with the tools available in script and sometimes overlook what
is readily available in VBA.

Steve


"ArielZusya" <(E-Mail Removed)> wrote in message
news:E164BC8B-2E81-40CE-BAF1-(E-Mail Removed)...
> Thanks Steve. Incidentally, is there any disadvantage to using this
> method
> vs using the environ method? After posting I changed my search tactic and
> discovered a list of environ variables and discovered I could use
> "userprofile" to return everything before "\desktop\" but before I decide
> which method to use I thought I'd ask if one is better or faster or
> otherwise
> preferable. Thanks!
>
> "Steve Yandl" wrote:
>
>> Here is one option to return the path to the current user's desktop as a
>> string.
>>
>> Set objShell = CreateObject("Shell.Application")
>> Set objFolderDsk = objShell.Namespace(&H10&)
>> strDsk = objFolderDsk.Self.Path
>> MsgBox strDsk
>> Set objShell = Nothing
>>
>> Steve
>>
>>
>>
>> "ArielZusya" <(E-Mail Removed)> wrote in message
>> news:040D98DB-C4DC-47A7-95DF-(E-Mail Removed)...
>> > I've got a quirky problem. The network admin folks here at my office
>> > have
>> > a
>> > bit of a strange naming convention for users. If you start as a part
>> > timer
>> > you get a username that looks something like pt[loc][initials] so for
>> > someone
>> > who is named John H. Smith starting part time at location number 04,
>> > his
>> > login would be pt04jhs. The trouble is that if John switches to full
>> > time
>> > his username changes to ft04jhs but his userprofile still points to the
>> > directory C:\documents and settings\pt04jhs\. I want to use vba to
>> > export
>> > (copy) a sheet from the workbook I'm in to a new workbook, save that
>> > workbook
>> > to the desktop, and close that workbook without prompting the user.
>> > (Incidentally, the rest of the naming convention for the file relies on
>> > a
>> > combo box on the main menu (frmMainMenu) form called cmbSelectDivision,
>> > just
>> > in case you're wondering why that's in there.) Here's my code right
>> > now:
>> >
>> > dim NameThatExport as string
>> > NameThatExport = "Division" +
>> > frmMainMenu.cmbSelectDivision.Value _
>> > + ".xls"
>> > Sheets("MyList").Select
>> > Sheets("MyList").Copy
>> > ActiveWorkbook.SaveAs Filename:= _
>> > "C:\Documents and Settings\" + Environ("username") _
>> > + "\Desktop\" + NameThatExport, FileFormat:=xlNormal, _
>> > Password:="", WriteResPassword:="", _
>> > ReadOnlyRecommended:=False, CreateBackup:=False _
>> > Windows(fileNm).Activate
>> > Application.CutCopyMode = False
>> > ActiveWorkbook.Close False
>> >
>> >
>> > The code works well for users who started full time and remained full
>> > time
>> > and for users who started part time and remained part time but for
>> > those
>> > who
>> > started part time and switched to full time they get no autonaming. Is
>> > there
>> > a way to use code to find the desktop other than the way I tried above?
>> > Thanks for your help!

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
save as - to any desktop Driftwood Microsoft Excel Programming 2 28th Jul 2009 04:35 PM
Re: can't save to Desktop ThePro Windows Vista General Discussion 0 13th Jul 2007 06:40 PM
Re: can't save to Desktop Spirit Windows Vista General Discussion 0 13th Jul 2007 05:21 PM
How do I save something to the desktop? =?Utf-8?B?SG93IGRvIEkgc2F2ZSBzb21ldGhpbmcgb24gbXkg Windows Vista File Management 1 24th Mar 2007 04:17 PM
How do I save to the desktop across OS's? Greg Little Microsoft Excel Programming 2 14th Dec 2004 10:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:11 PM.