Avatar billede puppetmaster Nybegynder
25. januar 2002 - 13:05 Der er 31 kommentarer og
1 løsning

VBA kode til automatisering

Hej

Jeg sidder med følgende kodestump:
Sub NyAftale()
    Dim myOLApp As New Outlook.Application
    Dim myOLItem As Outlook.AppointmentItem
    Set myOLItem = myOLApp.CreateItem(olAppointmentItem)
    With myOLItem
        .ReminderSet = False
        .BusyStatus = olOutOfOffice
        .Start = Now
        .Duration = 60
       
    End With
myOLItem.Display
End Sub

Denne oprette en ny aftale, som starter når brugeren kører koden og slutter 60 min senere.
Mit problem er at jeg gerne vil have koden til at oprette en ny aftale som varer i det tidsrum som brugeren har markeret med markøren i stedet. Kan det lade sig gøre?
Avatar billede terry Ekspert
25. januar 2002 - 13:07 #1
hi puppetmaster>
"som brugeren har markeret med markøren i stedet" ?
Avatar billede puppetmaster Nybegynder
25. januar 2002 - 13:15 #2
Ja, det lyder lidt goofy.....sidder bare og roder lidt rundt........når en bruger har markeret et tidsrum for en ny aftale og skrevet "emne", skal det være muligt at aktivere en makro (VBA) der udfører ovenstående. Altså, sætter påmindelse = falsk, vis tidspunkt som = optaget og slutter med at gemme aftalen.
Avatar billede dimle Nybegynder
25. januar 2002 - 13:23 #3
Hvor vil du køre programmet fra?? Har du lavet dit eget program eller??
Avatar billede dimle Nybegynder
25. januar 2002 - 13:25 #4
Ej det kunne godt misforståes... Jeg mener hvor indtaster bruger det tidsrum som han vil have?? Fra et program du har lavet eller i Outlook??
Avatar billede puppetmaster Nybegynder
25. januar 2002 - 13:27 #5
Nej, han/hun markerer det med musen i kalenderen eller med [Shift][pil-op/pil-ned]
Avatar billede puppetmaster Nybegynder
25. januar 2002 - 13:28 #6
og trykker derefter på en genvejstast (det hele er for at undgå at bruge musen mere end højst nødvendigt!), som afspiller makroen (VBA-modulet)som udfører ovenstående.
Avatar billede terry Ekspert
25. januar 2002 - 13:47 #7
Ok, so its in Oulook VBA? I havent worked with Outlook VBA so much, but is it necessary to create a new instance of Outlook to di this?
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 08:25 #8
Damn, I answered your question yesterday, terry, guess some update thingy must have gone wrong...posting again:
no, it's not necessary to create a new istance of outlook to do it. All I want is a pointer to find out HOW to "read" which time-period the user has selected.
Avatar billede terry Ekspert
28. januar 2002 - 08:28 #9
hehe! I had the same problem yesterday too, spend an hour putting an answer together and it was gone next time I looked?
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 08:31 #10
:( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :(
Avatar billede terry Ekspert
28. januar 2002 - 08:31 #11
I agree :(
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 08:33 #12
You mean to tell me, that you've got the solution to my problem? (or was that for another problem?)
Avatar billede terry Ekspert
28. januar 2002 - 08:39 #13
Sorry, answer was to another question :o(
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 08:42 #14
Ok.
You see, I was thinking..............when you create a new appointment in the calendar, by double-clicking, outlook suggests the "duration" of the appointment. It's that object that I wanna work with, only Q is, how to obtain it?!
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 08:45 #15
There's an object collection called ActiveWindow, perhaps I can put that to good use?
Avatar billede terry Ekspert
28. januar 2002 - 08:49 #16
In Outlook you can right click selected period and then choose New Appointment, is it possible to catch the right click event? If so, can you debug and get hold of these values in code (do you know the names of the properties you want to work with?
Have you trued to catch your "genvejstast", can you?
Avatar billede terry Ekspert
28. januar 2002 - 08:50 #17
I havae good bokk on Outlook but its at home, if I get tiem this evening I will take a look
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 08:53 #18
Yes, the properties are called "Start" and "End".
.Start = "The selected start date/time
.End  = "The selected end date/time"
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 08:54 #19
Thanks a lot, terry, I'll double the points (atleast).
Avatar billede terry Ekspert
28. januar 2002 - 08:57 #20
but can you catch your genvejstast?
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 09:11 #21
I don't know, can't I? (ups, perhaps you don't know that genvejstast....(damn, forgot the dictionary at home!).....well, forinstance, [ctrl][alt][delete] is a genvejstast.......so is [ctrl][bold] i Word, does that help a bit?)
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 10:22 #22
Here's what I want: the "Selected_Appointment object".
Avatar billede terry Ekspert
28. januar 2002 - 10:25 #23
Yes I know what a "genvejstast" is but I just wanted to know if you can call your macro (does it get called) when you use the  "genvejstast" ?

If you can, and you know your .start and .end then you should be able to code your .Start and .duration for the new appointment.

The .start and .end you refer to 08:53, are you SURE these are the tiems the user has selected? If so, then lets call them NewObj.Start and NewObj.End

So your code for creating a new would be
With myOLItem
        .ReminderSet = False
        .BusyStatus = olOutOfOffice
        .Start = NewObj.Start
        .End  = NewObj.End
        '.Duration = 60
       
    End With

Or ?


these times are on a NOT YET created appointment and you are going to create ANOTHER. This means that you have to CANCEL
Avatar billede terry Ekspert
28. januar 2002 - 10:27 #24
Didnt see your comment from 10:22!

With myOLItem
        .ReminderSet = False
        .BusyStatus = olOutOfOffice
        .Start = Selected_Appointment.Start
        .End  = Selected_Appointment.End
        '.Duration = 60
       
    End With
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 11:09 #25
I'll explain it again a bit more clearly, if I can:
I the Outlook calendar, I click on the vertical bar that selects the timeperiod from 12:00 to 12:30, drag the mouse to, say, 14:00, release the mouse and rightclick on the new appointment. The shortcut menu has an option called "Ny aftale", which, if I click it, opens a new appointment, that has starttime = 12:00 and finishtime = 14:00.
I want a macro (VBA) to do that for me, to automatically set the timeperiod, reminder and busystatus. But HOW do I obtain the start and end time? Outlook does it, othervise, it'd just make a new appointment starting at 12:00 and lasting 30 mins. So, HOW if Outlook can "get" those properties, so can I.
Avatar billede terry Ekspert
28. januar 2002 - 11:14 #26
Yes I undersatnd whatitis you want, but I thought you could get hold of these properties (Yes, the properties are called "Start" and "End".
.Start = "The selected start date/time
.End  = "The selected end date/time" )
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 11:29 #27
I thought so too.....but I have no idea where to get 'em from......can't find any info on "selected start/end date/time" anywhere......*sigh!*
Avatar billede puppetmaster Nybegynder
28. januar 2002 - 11:31 #28
CurrentItem Property Example

This Visual Basic for Applications example uses the CurrentItem property to obtain the current item that the user is viewing. If there is no currently open item, an error will be returned.

Set myOlApp = CreateObject("Outlook.Application")
On Error Resume Next
Set myItem = myOlApp.ActiveInspector.CurrentItem
Avatar billede terry Ekspert
29. januar 2002 - 09:17 #29
hi puppetmaster!
Sorry, but I didnt get time to look at your problem yesterday evening. I have taken the book withme to work, so I will see if I can find something today.
The book I have is Building Applications with Outlook 2000 ISBN 0-7356-0581-5 if your interested.
Avatar billede terry Ekspert
30. januar 2002 - 12:19 #30
Hi again!
puppetmaster, I just dont seem to be able to find a soltion to your question, I will keep it in mind and if something does come up then I wil get in touch!
Avatar billede puppetmaster Nybegynder
31. januar 2002 - 08:43 #31
Hi terry, you'll get your points for trying, I found the solution myself.
Posting it just for the hell of it:

Sub Ledig()
GetCurrentItem
  With GetCurrentItem
    .ReminderSet = False
    .BusyStatus = olFree
    .Save
  End With
End Sub

Function GetCurrentItem() As Object
  Dim objApp As Application
  Dim objSel As Selection
  Dim objItem As Object
     
  Set objApp = CreateObject("Outlook.Application")
  If objApp.ActiveWindow.Class = olExplorer Then
    Set objSel = objApp.ActiveExplorer.Selection
      If objSel.Count > 0 Then
        Set objItem = objSel.Item(1)
      End If
  End If
  Set GetCurrentItem = objItem
  Set objItem = Nothing
  Set objSel = Nothing
  Set objApp = Nothing
End Function
Avatar billede terry Ekspert
31. januar 2002 - 10:02 #32
Hi and thanks, but it wasnt necessary :o)
Where did you find the solution?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester