25. januar 2002 - 13:05Der 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?
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.
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.
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.
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?!
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?
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?)
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
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.
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" )
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
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.
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!
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
Hi and thanks, but it wasnt necessary :o) Where did you find the solution?
Synes godt om
Ny brugerNybegynder
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.