通过描述其路径的字符串设置文件夹对象

时间:2019-02-20 15:55:11

标签: vba object outlook

在MS Outlook(2016)中,我正在VBA程序上进行工作,以更快地将某些单独选择的电子邮件存档到我的电子邮件存档中的某些文件夹中。

我有一个程序可以在手动寻址目标文件夹时发挥作用:

'[...]
Dim MoveToFolder As Outlook.MAPIFolder
'[...]
Set MoveToFolder = ns.Folders("Archive").Folders("Projekte-Archiv").Folders("P03_NetRef")
'[...]

通过此步骤,过程将知道将预选电子邮件移动到哪个文件夹。

现在是我的问题:

我试图通过字符串变量设置“ MoveToFolder”文件夹对象,并为其提供所有必需的数据。

为什么要执行此操作:将文件夹数据作为字符串变量移交将使我可以对需要的层次结构级别的所有文件夹使用相同的过程。

这是我使用CType函数想到的:

'[...]
Dim MoveToFolder As Outlook.MAPIFolder
'[...]
Set MoveToFolder = CType("ns.Folders(""Archive"").Folders(""Projekte-Archiv"").Folders(""P03_NetRef"")", Outlook.MAPIFolder)
'[...]

(这个想法当然是在下一步中通过一个变量插入字符串,而不是像例子中那样用明文书写。)

这不起作用。对象类型'Outlook.MAPIFolder'导致编译错误(“未找到方法或数据对象”)。

最新见识

正如我稍后所了解的,CType()函数在VBA中不可用(与VB.net相反)。

1 个答案:

答案 0 :(得分:1)

未经测试:

import Foundation
import Foundation
import ARKit
import SceneKit
import GameplayKit

class EntityManager {
    var toRemove = Set<GKEntity>()
let costQuirk = 20
lazy var componentSystems: [GKComponentSystem] = {
    let moveSystem = GKComponentSystem(componentClass: MoveComponent.self)
    let meleeSystem = GKComponentSystem(componentClass: MeleeComponent.self)
    let firingSystem = GKComponentSystem(componentClass: ParticleComponent.self)
    let castleSystem = GKComponentSystem(componentClass: HeroComponent.self)
    let heroSystem = GKComponentSystem(componentClass: HeroComponent.self)
    let aiSystem = GKComponentSystem(componentClass: AiComponent.self)
    let nodeComponent = GKComponentSystem(componentClass: NodeComponent.self)
    return [moveSystem, meleeSystem, firingSystem, castleSystem, aiSystem,heroSystem,nodeComponent]
}()

// 1
var entities: Set<GKEntity>

let scene: SCNScene

// 2
init(scene: SCNScene) {
    self.scene = scene
    self.entities = Set<GKEntity>()
}

// 3
func add(_ entity: GKEntity) {

    if let spriteNode = entity.component(ofType: SpriteComponent.self)?.node {
        scene.rootNode.addChildNode(spriteNode)
        let speed = Int.random(in: 7 ... 10)
         let smoke = SCNParticleSystem(named: "art.scnassets/Models/spawnSmoke.scnp", inDirectory: nil)
        let smokeNode = SCNNode()
        spriteNode.addChildNode(smokeNode)
        print("Monster Added")
    }
    for componentSystem in componentSystems {
        componentSystem.addComponent(foundIn: entity)
    }
      entities.insert(entity)
}

// 4
func remove(_ entity: GKEntity) {
    if let spriteNode = entity.component(ofType: SpriteComponent.self)?.node {
        let confetti = SCNParticleSystem(named: "Media.scnassets/Fire.scnp", inDirectory: nil)
        confetti?.loops = false
        confetti?.particleLifeSpan = 0.05
        confetti?.particleSize -= 1
        confetti?.particleIntensity -= 0.5
        print("Making Explosion")
        if let geometry = spriteNode.geometry {
        confetti?.emitterShape = geometry
        }
        spriteNode.addParticleSystem(confetti!)
        print("Exploding Node!")
        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3))  {
        spriteNode.removeFromParentNode()
        spriteNode.removeAllActions()
        self.entities.remove(entity)
        self.toRemove.insert(entity)

    }

    }
        entities.remove(entity)
}
func update(_ deltaTime: CFTimeInterval) {
    // 1
    for system in componentSystems {
        system.update(deltaTime: deltaTime)
    }

    // 2
    for currentRemove in toRemove {
        for componentSystem in componentSystems {
            componentSystem.removeComponent(foundIn: currentRemove)
        }
    }
    toRemove.removeAll()

}
func castle(for team: Team) -> GKEntity? {
    for entity in self.entities {
        if let teamComponent = entity.component(ofType: TeamComponent.self),
            let _ = entity.component(ofType: HeroComponent.self) {
            if teamComponent.team == team {
                return entity
            }
        }
    }
    return nil
}

func spawnQuirk(team: Team , positon: SCNVector3) {
    // 1
    guard let teamEntity = castle(for: team) else {return}


    // 2
    if  let teamCastleComponent = teamEntity.component(ofType: HeroComponent.self) {
    if teamCastleComponent.coins < costQuirk , team == .team1{
        return
    }
                teamCastleComponent.coins -= costQuirk
    }



    // 3
    guard let floor = GAMEFLOOR as? SCNNode else {return}
    let monster = Quirk(team: team, entityManager: self, floor:floor)
    if let spriteComponent = monster.component(ofType: SpriteComponent.self) {
        let randomX = Float.random(in: -10.0 ... -0.0)
        let randomZ = Float.random(in: -10.0 ... -1.0)
        spriteComponent.node.position = positon
        let teamRing = SCNParticleSystem(named: "Media.scnassets/teamRing.scnp", inDirectory: nil)

        switch team {
        case .team1 :
            teamRing?.particleColor = .blue
        case .team2:
            teamRing?.particleColor = .red


        }
        spriteComponent.node.addParticleSystem(teamRing!)
    }


    add(monster)

}
func spawnZap(_ team: Team, positon: SCNVector3) {
    guard let teamEntity = castle(for: team) else {return}

    if  let teamCastleComponent = teamEntity.component(ofType: HeroComponent.self) {
        if teamCastleComponent.coins < costZap , team == .team1{
            return
        }

    teamCastleComponent.coins -= costZap

    let monster = Zap(team: team, entityManager: self)
if let spriteComponent = monster.component(ofType: SpriteComponent.self) {
    let randomX = Float.random(in: -10.0 ... -0.0)
    let randomZ = Float.random(in: -10.0 ... -1.0)
    spriteComponent.node.position = positon

    }
        add(monster)
}
}

func spawnMunch(_ team: Team, positon: SCNVector3) {
    guard let teamEntity = castleForTeam(team),
        let teamCastleComponent = teamEntity.component(ofType: HeroComponent.self),
        let teamSpriteComponent = teamEntity.component(ofType: SpriteComponent.self) else {
            return
    }

    if teamCastleComponent.coins < costMunch {
        return
    }

    teamCastleComponent.coins -= costMunch
    guard let floor = GAMEFLOOR as? SCNNode else {return}

    let monster = Munch(team: team, entityManager: self, floor:floor)
          if let spriteComponent = monster.component(ofType: SpriteComponent.self) {
    let randomX = Float.random(in: -10.0 ... -0.0)
    let randomZ = Float.random(in: -10.0 ... -1.0)
    spriteComponent.node.position = positon

}
        add(monster)
}
func entitiesForTeam(_ team: Team) -> [GKEntity] {

    return entities.compactMap{ entity in
        if let teamComponent = entity.component(ofType: TeamComponent.self) {
            if teamComponent.team == team {
                return entity
            }
        }
        return nil
    }

}

func moveComponentsForTeam(_ team: Team) -> [MoveComponent] {
    let entities = entitiesForTeam(team)
    var moveComponents = [MoveComponent]()
    for entity in entities {
        if let moveComponent = entity.component(ofType: MoveComponent.self) {
            moveComponents.append(moveComponent)
        }
    }
    return moveComponents
}

func castleForTeam(_ team: Team) -> GKEntity? {
    for entity in entities {
        if let teamComponent = entity.component(ofType: TeamComponent.self),
            let _ = entity.component(ofType: HeroComponent.self) {
            if teamComponent.team == team {
                return entity
            }
        }
    }
    return nil
}
func entities(for team: Team) -> [GKEntity] {
    return entities.compactMap{ entity in
        if let teamComponent = entity.component(ofType: TeamComponent.self) {
            if teamComponent.team == team {
                return entity
            }
        }
        return nil
    }
}

func moveComponents(for team: Team) -> [MoveComponent] {
    let entitiesToMove = entities(for: team)
    var moveComponents = [MoveComponent]()
    for entity in entitiesToMove {
        if let moveComponent = entity.component(ofType:    MoveComponent.self) {
            moveComponents.append(moveComponent)
        }
    }
    return moveComponents
}
}

解析路径的函数:

Set MoveToFolder = GetFolder(ns, "Archive|Projekte-Archiv|P03_NetRef")